@promptbook/markdown-utils 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('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', 'crypto-js/enc-hex', 'crypto-js/sha256', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.hexEncoder, global.sha256, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, 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('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2190,11 +2190,29 @@
|
|
|
2190
2190
|
*/
|
|
2191
2191
|
function createTask(options) {
|
|
2192
2192
|
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2193
|
-
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(
|
|
2193
|
+
var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
|
|
2194
2194
|
var partialResultSubject = new rxjs.BehaviorSubject({});
|
|
2195
2195
|
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2196
2196
|
partialResultSubject.next(newOngoingResult);
|
|
2197
2197
|
});
|
|
2198
|
+
finalResultPromise
|
|
2199
|
+
.catch(function (error) {
|
|
2200
|
+
// console.error('!!!!! Task failed:', error);
|
|
2201
|
+
partialResultSubject.error(error);
|
|
2202
|
+
})
|
|
2203
|
+
.then(function (value) {
|
|
2204
|
+
// console.error('!!!!! Task finished:', value);
|
|
2205
|
+
if (value) {
|
|
2206
|
+
try {
|
|
2207
|
+
assertsTaskSuccessful(value);
|
|
2208
|
+
partialResultSubject.next(value);
|
|
2209
|
+
}
|
|
2210
|
+
catch (error) {
|
|
2211
|
+
partialResultSubject.error(error);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
partialResultSubject.complete();
|
|
2215
|
+
});
|
|
2198
2216
|
function asPromise(options) {
|
|
2199
2217
|
return __awaiter(this, void 0, void 0, function () {
|
|
2200
2218
|
var _a, isCrashedOnError, finalResult;
|
|
@@ -2205,7 +2223,9 @@
|
|
|
2205
2223
|
return [4 /*yield*/, finalResultPromise];
|
|
2206
2224
|
case 1:
|
|
2207
2225
|
finalResult = _b.sent();
|
|
2226
|
+
console.error('!!!!! finalResult:', finalResult);
|
|
2208
2227
|
if (isCrashedOnError) {
|
|
2228
|
+
console.error('!!!!! isCrashedOnError:', finalResult);
|
|
2209
2229
|
assertsTaskSuccessful(finalResult);
|
|
2210
2230
|
}
|
|
2211
2231
|
return [2 /*return*/, finalResult];
|
|
@@ -2218,9 +2238,10 @@
|
|
|
2218
2238
|
taskId: taskId,
|
|
2219
2239
|
asPromise: asPromise,
|
|
2220
2240
|
asObservable: function () {
|
|
2221
|
-
return
|
|
2222
|
-
|
|
2223
|
-
|
|
2241
|
+
return partialResultSubject.asObservable();
|
|
2242
|
+
},
|
|
2243
|
+
get currentValue() {
|
|
2244
|
+
return partialResultSubject.value;
|
|
2224
2245
|
},
|
|
2225
2246
|
};
|
|
2226
2247
|
}
|
|
@@ -3650,7 +3671,7 @@
|
|
|
3650
3671
|
value = value.replace(/\.html$/, '');
|
|
3651
3672
|
}
|
|
3652
3673
|
else if (isValidFilePath(value)) {
|
|
3653
|
-
value =
|
|
3674
|
+
value = path.basename(value);
|
|
3654
3675
|
// Note: Keeping extension in the name
|
|
3655
3676
|
}
|
|
3656
3677
|
value = value.split('/').join('-');
|
|
@@ -3756,9 +3777,9 @@
|
|
|
3756
3777
|
}
|
|
3757
3778
|
basename = url.split('/').pop() || titleToName(url);
|
|
3758
3779
|
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3759
|
-
rootDirname_1 =
|
|
3760
|
-
filepath =
|
|
3761
|
-
return [4 /*yield*/, tools.fs.mkdir(
|
|
3780
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3781
|
+
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));
|
|
3782
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3762
3783
|
case 2:
|
|
3763
3784
|
_h.sent();
|
|
3764
3785
|
_g = (_f = Buffer).from;
|
|
@@ -3768,7 +3789,7 @@
|
|
|
3768
3789
|
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3769
3790
|
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."));
|
|
3770
3791
|
}
|
|
3771
|
-
return [4 /*yield*/, tools.fs.writeFile(
|
|
3792
|
+
return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
|
|
3772
3793
|
case 4:
|
|
3773
3794
|
_h.sent();
|
|
3774
3795
|
// TODO: [💵] Check the file security
|
|
@@ -3784,7 +3805,7 @@
|
|
|
3784
3805
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
3785
3806
|
// <- TODO: [🧠] What is the best error type here`
|
|
3786
3807
|
}
|
|
3787
|
-
filename_1 =
|
|
3808
|
+
filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
|
|
3788
3809
|
fileExtension = getFileExtension(filename_1);
|
|
3789
3810
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3790
3811
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|