@promptbook/core 0.55.0 → 0.56.0-2
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 +3 -2
- package/esm/index.es.js +31 -262
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/anthropic-claude.index.d.ts +2 -0
- package/esm/typings/_packages/azure-openai.index.d.ts +2 -0
- package/esm/typings/_packages/cli.index.d.ts +2 -0
- package/esm/typings/_packages/core.index.d.ts +3 -3
- package/esm/typings/_packages/execute-javascript.index.d.ts +2 -0
- package/esm/typings/_packages/{mock.index.d.ts → fake-llm.index.d.ts} +2 -1
- package/esm/typings/_packages/langtail.index.d.ts +2 -0
- package/esm/typings/_packages/node.index.d.ts +4 -0
- package/esm/typings/_packages/openai.index.d.ts +2 -0
- package/esm/typings/_packages/remote-client.index.d.ts +2 -0
- package/esm/typings/_packages/remote-server.index.d.ts +2 -0
- package/esm/typings/_packages/types.index.d.ts +3 -2
- package/esm/typings/_packages/utils.index.d.ts +2 -1
- package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +0 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -10
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +0 -3
- package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -3
- package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +0 -4
- package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +0 -3
- package/package.json +1 -1
- package/umd/index.umd.js +34 -265
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/anthropic-claude.index.d.ts +2 -0
- package/umd/typings/_packages/azure-openai.index.d.ts +2 -0
- package/umd/typings/_packages/cli.index.d.ts +2 -0
- package/umd/typings/_packages/core.index.d.ts +3 -3
- package/umd/typings/_packages/execute-javascript.index.d.ts +2 -0
- package/umd/typings/_packages/{mock.index.d.ts → fake-llm.index.d.ts} +2 -1
- package/umd/typings/_packages/langtail.index.d.ts +2 -0
- package/umd/typings/_packages/node.index.d.ts +4 -0
- package/umd/typings/_packages/openai.index.d.ts +2 -0
- package/umd/typings/_packages/remote-client.index.d.ts +2 -0
- package/umd/typings/_packages/remote-server.index.d.ts +2 -0
- package/umd/typings/_packages/types.index.d.ts +3 -2
- package/umd/typings/_packages/utils.index.d.ts +2 -1
- package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +0 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -10
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +0 -3
- package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -3
- package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +0 -4
- package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +0 -3
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { OPENAI_MODELS } from '../execution/plugins/llm-execution-tools/openai/openai-models';
|
|
2
2
|
import { OpenAiExecutionTools } from '../execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools';
|
|
3
3
|
import { OpenAiExecutionToolsOptions } from '../execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions';
|
|
4
|
+
import { PROMPTBOOK_VERSION } from '../version';
|
|
5
|
+
export { PROMPTBOOK_VERSION };
|
|
4
6
|
export { OPENAI_MODELS, OpenAiExecutionTools, OpenAiExecutionToolsOptions };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { RemoteServerOptions } from '../execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions';
|
|
2
2
|
import { RemoteLlmExecutionTools } from '../execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools';
|
|
3
3
|
import { RemoteLlmExecutionToolsOptions } from '../execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions';
|
|
4
|
+
import { PROMPTBOOK_VERSION } from '../version';
|
|
5
|
+
export { PROMPTBOOK_VERSION };
|
|
4
6
|
export { RemoteLlmExecutionTools, RemoteLlmExecutionToolsOptions, RemoteServerOptions };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { RemoteServerOptions } from '../execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions';
|
|
2
2
|
import { startRemoteServer } from '../execution/plugins/llm-execution-tools/remote/startRemoteServer';
|
|
3
|
+
import { PROMPTBOOK_VERSION } from '../version';
|
|
4
|
+
export { PROMPTBOOK_VERSION };
|
|
3
5
|
export { RemoteServerOptions, startRemoteServer };
|
|
@@ -20,8 +20,9 @@ import type { TaskProgress } from '../types/TaskProgress';
|
|
|
20
20
|
import type { ExecutionReportJson } from '../types/execution-report/ExecutionReportJson';
|
|
21
21
|
import type { string_char_emoji } from '../types/typeAliasEmoji';
|
|
22
22
|
import type { client_id, string_char, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
|
|
23
|
-
import { FromtoItems } from '../utils/FromtoItems';
|
|
24
|
-
|
|
23
|
+
import type { FromtoItems } from '../utils/FromtoItems';
|
|
24
|
+
import { PROMPTBOOK_VERSION } from '../version';
|
|
25
|
+
export type { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PROMPTBOOK_VERSION, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
|
|
25
26
|
/**
|
|
26
27
|
* TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
|
|
27
28
|
*/
|
|
@@ -47,7 +47,8 @@ import { union } from '../utils/sets/union';
|
|
|
47
47
|
import { trimCodeBlock } from '../utils/trimCodeBlock';
|
|
48
48
|
import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
|
|
49
49
|
import { unwrapResult } from '../utils/unwrapResult';
|
|
50
|
-
|
|
50
|
+
import { PROMPTBOOK_VERSION } from '../version';
|
|
51
|
+
export { forEachAsync, PROMPTBOOK_VERSION };
|
|
51
52
|
export { extractAllBlocksFromMarkdown, // <- [🌻]
|
|
52
53
|
extractAllListItemsFromMarkdown, extractBlock, // <- [🌻]
|
|
53
54
|
extractOneBlockFromMarkdown, extractParameters, extractVariables, isValidJsonString, parseNumber, // <- [🌻]
|
package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts
CHANGED
|
@@ -10,6 +10,5 @@ import type { PostprocessingFunction } from '../../script-execution-tools/javasc
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function $fakeTextToExpectations(expectations: Expectations, postprocessing?: Array<PostprocessingFunction>): Promise<string>;
|
|
12
12
|
/**
|
|
13
|
-
* TODO: [🚏] Implement better - create FakeLLM from this
|
|
14
13
|
* TODO: [💝] Unite object for expecting amount and format - use here also a format
|
|
15
14
|
*/
|
|
@@ -41,13 +41,3 @@ type CreatePromptbookLibraryFromDirectoryOptions = {
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
|
|
43
43
|
export {};
|
|
44
|
-
/***
|
|
45
|
-
* TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
|
|
46
|
-
* [🍓][🚯] maybe make `@promptbook/library` package
|
|
47
|
-
* TODO: Fix the dynamic import issue in Webpack (! Not working !)
|
|
48
|
-
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
49
|
-
* > Critical dependency: the request of a dependency is an expression
|
|
50
|
-
*
|
|
51
|
-
* Note: [1] Using require(just('fs/promises')) to allow
|
|
52
|
-
* the `@promptbook/core` work for both Node.js and browser environments
|
|
53
|
-
*/
|
|
@@ -21,6 +21,3 @@ import type { PromptbookLibrary } from '../PromptbookLibrary';
|
|
|
21
21
|
* @private Just internal tool for other constructor functions
|
|
22
22
|
*/
|
|
23
23
|
export declare function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory: Promise<Array<PromptbookJson | PromptbookString>> | (() => Promise<Array<PromptbookJson | PromptbookString>>)): PromptbookLibrary;
|
|
24
|
-
/***
|
|
25
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
26
|
-
*/
|
|
@@ -11,6 +11,3 @@ import { SimplePromptbookLibrary } from '../SimplePromptbookLibrary';
|
|
|
11
11
|
* @returns PromptbookLibrary
|
|
12
12
|
*/
|
|
13
13
|
export declare function createPromptbookLibraryFromSources(...promptbookSources: Array<PromptbookJson | PromptbookString>): SimplePromptbookLibrary;
|
|
14
|
-
/***
|
|
15
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
16
|
-
*/
|
|
@@ -24,7 +24,3 @@ type CreatePromptbookLibraryFromUrlyOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function createPromptbookLibraryFromUrl(url: string_url | URL, options: CreatePromptbookLibraryFromUrlyOptions): Promise<PromptbookLibrary>;
|
|
26
26
|
export {};
|
|
27
|
-
/***
|
|
28
|
-
* TODO: [⚖] Compatible with remote server
|
|
29
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
30
|
-
*/
|
|
@@ -10,6 +10,3 @@ import type { PromptbookLibrary } from '../PromptbookLibrary';
|
|
|
10
10
|
* @returns PromptbookLibrary
|
|
11
11
|
*/
|
|
12
12
|
export declare function createPromptbookSublibrary(library: PromptbookLibrary, predicate: (url: string_promptbook_url) => boolean): PromptbookLibrary;
|
|
13
|
-
/***
|
|
14
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
15
|
-
*/
|
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('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.moment));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, moment) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -454,7 +454,7 @@
|
|
|
454
454
|
/**
|
|
455
455
|
* The version of the Promptbook library
|
|
456
456
|
*/
|
|
457
|
-
var PROMPTBOOK_VERSION = '0.
|
|
457
|
+
var PROMPTBOOK_VERSION = '0.56.0-1';
|
|
458
458
|
|
|
459
459
|
/**
|
|
460
460
|
* Parses the template and returns the list of all parameter names
|
|
@@ -3349,36 +3349,6 @@
|
|
|
3349
3349
|
return uncertainNumber;
|
|
3350
3350
|
}
|
|
3351
3351
|
|
|
3352
|
-
/**
|
|
3353
|
-
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
3354
|
-
*/
|
|
3355
|
-
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
3356
|
-
/**
|
|
3357
|
-
* Detects if the code is running in a Node.js environment
|
|
3358
|
-
*/
|
|
3359
|
-
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
3360
|
-
/**
|
|
3361
|
-
* Detects if the code is running in a web worker
|
|
3362
|
-
*/
|
|
3363
|
-
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
3364
|
-
|
|
3365
|
-
/**
|
|
3366
|
-
* Returns the same value that is passed as argument.
|
|
3367
|
-
* No side effects.
|
|
3368
|
-
*
|
|
3369
|
-
* Note: It can be usefull for leveling indentation
|
|
3370
|
-
*
|
|
3371
|
-
* @param value any values
|
|
3372
|
-
* @returns the same values
|
|
3373
|
-
*/
|
|
3374
|
-
function just(value) {
|
|
3375
|
-
if (value === undefined) {
|
|
3376
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3377
|
-
return undefined;
|
|
3378
|
-
}
|
|
3379
|
-
return value;
|
|
3380
|
-
}
|
|
3381
|
-
|
|
3382
3352
|
/**
|
|
3383
3353
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
3384
3354
|
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
@@ -3498,9 +3468,6 @@
|
|
|
3498
3468
|
}
|
|
3499
3469
|
return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
3500
3470
|
}
|
|
3501
|
-
/***
|
|
3502
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
3503
|
-
*/
|
|
3504
3471
|
|
|
3505
3472
|
/**
|
|
3506
3473
|
* Constructs Promptbook from async sources
|
|
@@ -3584,226 +3551,6 @@
|
|
|
3584
3551
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3585
3552
|
};
|
|
3586
3553
|
}
|
|
3587
|
-
/***
|
|
3588
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
3589
|
-
*/
|
|
3590
|
-
|
|
3591
|
-
/**
|
|
3592
|
-
* Constructs Promptbook from given directory
|
|
3593
|
-
*
|
|
3594
|
-
* Note: Works only in Node.js environment because it reads the file system
|
|
3595
|
-
*
|
|
3596
|
-
* @param path - path to the directory with promptbooks
|
|
3597
|
-
* @param options - Misc options for the library
|
|
3598
|
-
* @returns PromptbookLibrary
|
|
3599
|
-
*/
|
|
3600
|
-
function createPromptbookLibraryFromDirectory(path, options) {
|
|
3601
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3602
|
-
var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
|
|
3603
|
-
var _this = this;
|
|
3604
|
-
return __generator(this, function (_f) {
|
|
3605
|
-
switch (_f.label) {
|
|
3606
|
-
case 0:
|
|
3607
|
-
if (!isRunningInNode()) {
|
|
3608
|
-
throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3609
|
-
}
|
|
3610
|
-
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
|
|
3611
|
-
library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3612
|
-
var fsPromises, readFile, fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
3613
|
-
var e_1, _a;
|
|
3614
|
-
return __generator(this, function (_b) {
|
|
3615
|
-
switch (_b.label) {
|
|
3616
|
-
case 0:
|
|
3617
|
-
if (isVerbose) {
|
|
3618
|
-
console.info("Creating promptbook library from path ".concat(path));
|
|
3619
|
-
}
|
|
3620
|
-
fsPromises = require(just('fs/promises') /* <- Note: [1] */);
|
|
3621
|
-
readFile = fsPromises.readFile;
|
|
3622
|
-
return [4 /*yield*/, listAllFiles(path, isRecursive)];
|
|
3623
|
-
case 1:
|
|
3624
|
-
fileNames = _b.sent();
|
|
3625
|
-
if (isVerbose) {
|
|
3626
|
-
console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
|
|
3627
|
-
}
|
|
3628
|
-
promptbooks = [];
|
|
3629
|
-
_loop_1 = function (fileName) {
|
|
3630
|
-
var promptbook, promptbookString, _c, _d, error_1, wrappedErrorMessage;
|
|
3631
|
-
return __generator(this, function (_e) {
|
|
3632
|
-
switch (_e.label) {
|
|
3633
|
-
case 0:
|
|
3634
|
-
_e.trys.push([0, 6, , 7]);
|
|
3635
|
-
promptbook = null;
|
|
3636
|
-
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 2];
|
|
3637
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3638
|
-
case 1:
|
|
3639
|
-
promptbookString = (_e.sent());
|
|
3640
|
-
promptbook = promptbookStringToJson(promptbookString);
|
|
3641
|
-
return [3 /*break*/, 5];
|
|
3642
|
-
case 2:
|
|
3643
|
-
if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 4];
|
|
3644
|
-
if (isVerbose) {
|
|
3645
|
-
console.info("Loading ".concat(fileName));
|
|
3646
|
-
}
|
|
3647
|
-
_d = (_c = JSON).parse;
|
|
3648
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3649
|
-
case 3:
|
|
3650
|
-
// TODO: Handle non-valid JSON files
|
|
3651
|
-
promptbook = _d.apply(_c, [_e.sent()]);
|
|
3652
|
-
return [3 /*break*/, 5];
|
|
3653
|
-
case 4:
|
|
3654
|
-
if (isVerbose) {
|
|
3655
|
-
console.info("Skipping file ".concat(fileName));
|
|
3656
|
-
}
|
|
3657
|
-
_e.label = 5;
|
|
3658
|
-
case 5:
|
|
3659
|
-
// ---
|
|
3660
|
-
if (promptbook !== null) {
|
|
3661
|
-
if (!promptbook.promptbookUrl) {
|
|
3662
|
-
if (isVerbose) {
|
|
3663
|
-
console.info("Not loading ".concat(fileName, " - missing URL"));
|
|
3664
|
-
}
|
|
3665
|
-
}
|
|
3666
|
-
else {
|
|
3667
|
-
if (isVerbose) {
|
|
3668
|
-
console.info("Loading ".concat(fileName));
|
|
3669
|
-
}
|
|
3670
|
-
if (!isCrashOnError) {
|
|
3671
|
-
// Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
|
|
3672
|
-
// But be handled in current try-catch block
|
|
3673
|
-
validatePromptbookJson(promptbook);
|
|
3674
|
-
}
|
|
3675
|
-
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
|
|
3676
|
-
promptbooks.push(promptbook);
|
|
3677
|
-
}
|
|
3678
|
-
}
|
|
3679
|
-
return [3 /*break*/, 7];
|
|
3680
|
-
case 6:
|
|
3681
|
-
error_1 = _e.sent();
|
|
3682
|
-
if (!(error_1 instanceof Error)) {
|
|
3683
|
-
throw error_1;
|
|
3684
|
-
}
|
|
3685
|
-
wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading promptbook from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
3686
|
-
if (isCrashOnError) {
|
|
3687
|
-
throw new PromptbookLibraryError(wrappedErrorMessage);
|
|
3688
|
-
}
|
|
3689
|
-
console.error(wrappedErrorMessage);
|
|
3690
|
-
return [3 /*break*/, 7];
|
|
3691
|
-
case 7: return [2 /*return*/];
|
|
3692
|
-
}
|
|
3693
|
-
});
|
|
3694
|
-
};
|
|
3695
|
-
_b.label = 2;
|
|
3696
|
-
case 2:
|
|
3697
|
-
_b.trys.push([2, 7, 8, 9]);
|
|
3698
|
-
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3699
|
-
_b.label = 3;
|
|
3700
|
-
case 3:
|
|
3701
|
-
if (!!fileNames_1_1.done) return [3 /*break*/, 6];
|
|
3702
|
-
fileName = fileNames_1_1.value;
|
|
3703
|
-
return [5 /*yield**/, _loop_1(fileName)];
|
|
3704
|
-
case 4:
|
|
3705
|
-
_b.sent();
|
|
3706
|
-
_b.label = 5;
|
|
3707
|
-
case 5:
|
|
3708
|
-
fileNames_1_1 = fileNames_1.next();
|
|
3709
|
-
return [3 /*break*/, 3];
|
|
3710
|
-
case 6: return [3 /*break*/, 9];
|
|
3711
|
-
case 7:
|
|
3712
|
-
e_1_1 = _b.sent();
|
|
3713
|
-
e_1 = { error: e_1_1 };
|
|
3714
|
-
return [3 /*break*/, 9];
|
|
3715
|
-
case 8:
|
|
3716
|
-
try {
|
|
3717
|
-
if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
|
|
3718
|
-
}
|
|
3719
|
-
finally { if (e_1) throw e_1.error; }
|
|
3720
|
-
return [7 /*endfinally*/];
|
|
3721
|
-
case 9: return [2 /*return*/, promptbooks];
|
|
3722
|
-
}
|
|
3723
|
-
});
|
|
3724
|
-
}); });
|
|
3725
|
-
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3726
|
-
return [4 /*yield*/, library.listPromptbooks()];
|
|
3727
|
-
case 1:
|
|
3728
|
-
_f.sent();
|
|
3729
|
-
_f.label = 2;
|
|
3730
|
-
case 2: return [2 /*return*/, library];
|
|
3731
|
-
}
|
|
3732
|
-
});
|
|
3733
|
-
});
|
|
3734
|
-
}
|
|
3735
|
-
/**
|
|
3736
|
-
* Reads all files in the directory
|
|
3737
|
-
*
|
|
3738
|
-
* @param path
|
|
3739
|
-
* @param isRecursive
|
|
3740
|
-
* @returns List of all files in the directory
|
|
3741
|
-
* @private internal function for `createPromptbookLibraryFromDirectory`
|
|
3742
|
-
*/
|
|
3743
|
-
function listAllFiles(path$1, isRecursive) {
|
|
3744
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3745
|
-
var fsPromises, readdir, dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_2_1;
|
|
3746
|
-
var e_2, _g;
|
|
3747
|
-
return __generator(this, function (_h) {
|
|
3748
|
-
switch (_h.label) {
|
|
3749
|
-
case 0:
|
|
3750
|
-
fsPromises = require(just('fs/promises') /* <- Note: [1] */);
|
|
3751
|
-
readdir = fsPromises.readdir;
|
|
3752
|
-
return [4 /*yield*/, readdir(path$1, {
|
|
3753
|
-
withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
|
|
3754
|
-
})];
|
|
3755
|
-
case 1:
|
|
3756
|
-
dirents = _h.sent();
|
|
3757
|
-
fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
|
|
3758
|
-
var name = _a.name;
|
|
3759
|
-
return path.join(path$1, name);
|
|
3760
|
-
});
|
|
3761
|
-
if (!isRecursive) return [3 /*break*/, 9];
|
|
3762
|
-
_h.label = 2;
|
|
3763
|
-
case 2:
|
|
3764
|
-
_h.trys.push([2, 7, 8, 9]);
|
|
3765
|
-
_a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
|
|
3766
|
-
_h.label = 3;
|
|
3767
|
-
case 3:
|
|
3768
|
-
if (!!_b.done) return [3 /*break*/, 6];
|
|
3769
|
-
dirent = _b.value;
|
|
3770
|
-
subPath = path.join(path$1, dirent.name);
|
|
3771
|
-
_d = (_c = fileNames.push).apply;
|
|
3772
|
-
_e = [fileNames];
|
|
3773
|
-
_f = [[]];
|
|
3774
|
-
return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
|
|
3775
|
-
case 4:
|
|
3776
|
-
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
3777
|
-
_h.label = 5;
|
|
3778
|
-
case 5:
|
|
3779
|
-
_b = _a.next();
|
|
3780
|
-
return [3 /*break*/, 3];
|
|
3781
|
-
case 6: return [3 /*break*/, 9];
|
|
3782
|
-
case 7:
|
|
3783
|
-
e_2_1 = _h.sent();
|
|
3784
|
-
e_2 = { error: e_2_1 };
|
|
3785
|
-
return [3 /*break*/, 9];
|
|
3786
|
-
case 8:
|
|
3787
|
-
try {
|
|
3788
|
-
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
3789
|
-
}
|
|
3790
|
-
finally { if (e_2) throw e_2.error; }
|
|
3791
|
-
return [7 /*endfinally*/];
|
|
3792
|
-
case 9: return [2 /*return*/, fileNames];
|
|
3793
|
-
}
|
|
3794
|
-
});
|
|
3795
|
-
});
|
|
3796
|
-
}
|
|
3797
|
-
/***
|
|
3798
|
-
* TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
|
|
3799
|
-
* [🍓][🚯] maybe make `@promptbook/library` package
|
|
3800
|
-
* TODO: Fix the dynamic import issue in Webpack (! Not working !)
|
|
3801
|
-
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
3802
|
-
* > Critical dependency: the request of a dependency is an expression
|
|
3803
|
-
*
|
|
3804
|
-
* Note: [1] Using require(just('fs/promises')) to allow
|
|
3805
|
-
* the `@promptbook/core` work for both Node.js and browser environments
|
|
3806
|
-
*/
|
|
3807
3554
|
|
|
3808
3555
|
/**
|
|
3809
3556
|
* Constructs Promptbook from remote Promptbase URL
|
|
@@ -3836,10 +3583,6 @@
|
|
|
3836
3583
|
});
|
|
3837
3584
|
});
|
|
3838
3585
|
}
|
|
3839
|
-
/***
|
|
3840
|
-
* TODO: [⚖] Compatible with remote server
|
|
3841
|
-
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
3842
|
-
*/
|
|
3843
3586
|
|
|
3844
3587
|
/**
|
|
3845
3588
|
* Creates PromptbookLibrary as a subset of another PromptbookLibrary
|
|
@@ -3919,9 +3662,36 @@
|
|
|
3919
3662
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3920
3663
|
};
|
|
3921
3664
|
}
|
|
3922
|
-
|
|
3923
|
-
|
|
3665
|
+
|
|
3666
|
+
/**
|
|
3667
|
+
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
3668
|
+
*/
|
|
3669
|
+
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
3670
|
+
/**
|
|
3671
|
+
* Detects if the code is running in a Node.js environment
|
|
3924
3672
|
*/
|
|
3673
|
+
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
3674
|
+
/**
|
|
3675
|
+
* Detects if the code is running in a web worker
|
|
3676
|
+
*/
|
|
3677
|
+
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
3678
|
+
|
|
3679
|
+
/**
|
|
3680
|
+
* Returns the same value that is passed as argument.
|
|
3681
|
+
* No side effects.
|
|
3682
|
+
*
|
|
3683
|
+
* Note: It can be usefull for leveling indentation
|
|
3684
|
+
*
|
|
3685
|
+
* @param value any values
|
|
3686
|
+
* @returns the same values
|
|
3687
|
+
*/
|
|
3688
|
+
function just(value) {
|
|
3689
|
+
if (value === undefined) {
|
|
3690
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3691
|
+
return undefined;
|
|
3692
|
+
}
|
|
3693
|
+
return value;
|
|
3694
|
+
}
|
|
3925
3695
|
|
|
3926
3696
|
/**
|
|
3927
3697
|
* Just testing imports and compatibility
|
|
@@ -4271,7 +4041,6 @@
|
|
|
4271
4041
|
exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
|
|
4272
4042
|
exports.checkExpectations = checkExpectations;
|
|
4273
4043
|
exports.createPromptbookExecutor = createPromptbookExecutor;
|
|
4274
|
-
exports.createPromptbookLibraryFromDirectory = createPromptbookLibraryFromDirectory;
|
|
4275
4044
|
exports.createPromptbookLibraryFromSources = createPromptbookLibraryFromSources;
|
|
4276
4045
|
exports.createPromptbookLibraryFromUrl = createPromptbookLibraryFromUrl;
|
|
4277
4046
|
exports.createPromptbookSublibrary = createPromptbookSublibrary;
|