@promptbook/utils 0.80.0 → 0.81.0-12
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 +13 -6
- package/esm/index.es.js +195 -55
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +15 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -6
- package/esm/typings/src/_packages/editable.index.d.ts +10 -0
- package/esm/typings/src/_packages/templates.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +12 -2
- package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
- package/esm/typings/src/config.d.ts +26 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -2
- package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
- package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -2
- package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
- package/esm/typings/src/other/templates/getBookTemplate.d.ts +19 -0
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
- package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +10 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +10 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +8 -0
- package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
- package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
- package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
- package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
- package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
- package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isPathRoot.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isPathRoot.test.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
- package/esm/typings/src/version.d.ts +7 -0
- package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +51 -0
- package/package.json +1 -1
- package/umd/index.umd.js +200 -55
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
- package/esm/typings/src/utils/formatNumber.d.ts +0 -6
- /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
- /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
- /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { string_parameter_value } from '../../types/typeAliases';
|
|
2
|
+
import type { really_unknown } from '../organization/really_unknown';
|
|
3
|
+
/**
|
|
4
|
+
* Function `valueToString` will convert the given value to string
|
|
5
|
+
* This is useful and used in the `templateParameters` function
|
|
6
|
+
*
|
|
7
|
+
* Note: This function is not just calling `toString` method
|
|
8
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
9
|
+
* See `VALUE_STRINGS`
|
|
10
|
+
*
|
|
11
|
+
* Note: There are 2 similar functions
|
|
12
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
13
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
14
|
+
*
|
|
15
|
+
* @public exported from `@promptbook/utils`
|
|
16
|
+
*/
|
|
17
|
+
export declare function valueToString(value: really_unknown): string_parameter_value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,6 +6,10 @@ import type { really_any } from '../organization/really_any';
|
|
|
6
6
|
* For example:
|
|
7
7
|
* - `Date` objects will be converted to string
|
|
8
8
|
*
|
|
9
|
+
* Note: There are 2 similar functions
|
|
10
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
11
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
12
|
+
*
|
|
9
13
|
* @private Internal helper function
|
|
10
14
|
*/
|
|
11
15
|
export declare function asSerializable(value: really_any): really_any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { string_dirname } from '../../../types/typeAliases';
|
|
2
|
+
import type { string_filename } from '../../../types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* Determines if the given path is a root path.
|
|
5
|
+
*
|
|
6
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
7
|
+
* @public exported from `@promptbook/utils`
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPathRoot(value: string_dirname | string_filename): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🍏] Make for MacOS paths
|
|
12
|
+
*/
|
|
@@ -2,15 +2,22 @@ import type { string_semantic_version } from './types/typeAliases';
|
|
|
2
2
|
/**
|
|
3
3
|
* The version of the Book language
|
|
4
4
|
*
|
|
5
|
+
* @generated
|
|
5
6
|
* @see https://github.com/webgptorg/book
|
|
6
7
|
*/
|
|
7
8
|
export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
8
9
|
/**
|
|
9
10
|
* The version of the Promptbook engine
|
|
10
11
|
*
|
|
12
|
+
* @generated
|
|
11
13
|
* @see https://github.com/webgptorg/promptbook
|
|
12
14
|
*/
|
|
13
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
|
+
/**
|
|
17
|
+
* @@@
|
|
18
|
+
*
|
|
19
|
+
* @generated
|
|
20
|
+
*/
|
|
14
21
|
export type string_promptbook_version = string_semantic_version;
|
|
15
22
|
/**
|
|
16
23
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ExecutionTools } from '../execution/ExecutionTools';
|
|
2
|
+
import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
|
|
3
|
+
import type { PipelineString } from '../pipeline/PipelineString';
|
|
4
|
+
import type { PrepareAndScrapeOptions } from '../prepare/PrepareAndScrapeOptions';
|
|
5
|
+
import type { string_filename } from '../types/typeAliases';
|
|
6
|
+
import type { string_pipeline_url } from '../types/typeAliases';
|
|
7
|
+
/**
|
|
8
|
+
* @see ./wizzard.ts `getPipeline` method
|
|
9
|
+
*
|
|
10
|
+
* @private usable through `ptbk run` and `@prompbook/wizzard`
|
|
11
|
+
*/
|
|
12
|
+
export declare function $getCompiledBook(tools: Required<Pick<ExecutionTools, 'fs' | 'fetch'>>, pipelineSource: string_filename | string_pipeline_url | PipelineString, options?: PrepareAndScrapeOptions): Promise<PipelineJson>;
|
|
13
|
+
/**
|
|
14
|
+
* TODO: Write unit test
|
|
15
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
16
|
+
*/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Promisable } from 'type-fest';
|
|
2
|
+
import type { ExecutionTools } from '../execution/ExecutionTools';
|
|
3
|
+
import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
|
|
4
|
+
import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
|
|
5
|
+
import type { PipelineString } from '../pipeline/PipelineString';
|
|
6
|
+
import type { TaskProgress } from '../types/TaskProgress';
|
|
7
|
+
import type { InputParameters } from '../types/typeAliases';
|
|
8
|
+
import type { string_filename } from '../types/typeAliases';
|
|
9
|
+
import type { string_pipeline_url } from '../types/typeAliases';
|
|
10
|
+
/**
|
|
11
|
+
* Look at `wizzard` for more details
|
|
12
|
+
*
|
|
13
|
+
* @private just for single instance
|
|
14
|
+
*/
|
|
15
|
+
declare class Wizzard {
|
|
16
|
+
/**
|
|
17
|
+
* @@@!!!!!!
|
|
18
|
+
*/
|
|
19
|
+
execute(book: string_pipeline_url, inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<PipelineExecutorResult>;
|
|
20
|
+
private executionTools;
|
|
21
|
+
/**
|
|
22
|
+
* @@@!!!
|
|
23
|
+
*
|
|
24
|
+
* @param pipelineSource
|
|
25
|
+
*/
|
|
26
|
+
getExecutionTools(): Promise<Required<Pick<ExecutionTools, 'fs' | 'fetch'>>>;
|
|
27
|
+
/**
|
|
28
|
+
* TODO: Make standalone function from this exported from node and used here and in `ptbk run`
|
|
29
|
+
* @@@!!!
|
|
30
|
+
*
|
|
31
|
+
* Strategies:
|
|
32
|
+
* 1) @@@!!!
|
|
33
|
+
* 2) @@@!!!
|
|
34
|
+
*
|
|
35
|
+
* @param pipelineSource
|
|
36
|
+
*/
|
|
37
|
+
getCompiledBook(pipelineSource: string_filename | string_pipeline_url | PipelineString): Promise<PipelineJson>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 🧙♂️ @@@
|
|
41
|
+
*
|
|
42
|
+
* @singleton
|
|
43
|
+
* @public exported from `@promptbook/wizzard`
|
|
44
|
+
*/
|
|
45
|
+
export declare const wizzard: Wizzard;
|
|
46
|
+
export {};
|
|
47
|
+
/**
|
|
48
|
+
* TODO: !!!!!! Mark in jsdoc as non-pure
|
|
49
|
+
* TODO: !!!!!! Add to readmes - one markdown here imported in all packages
|
|
50
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
51
|
+
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -12,20 +12,86 @@
|
|
|
12
12
|
/**
|
|
13
13
|
* The version of the Book language
|
|
14
14
|
*
|
|
15
|
+
* @generated
|
|
15
16
|
* @see https://github.com/webgptorg/book
|
|
16
17
|
*/
|
|
17
18
|
var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
18
19
|
/**
|
|
19
20
|
* The version of the Promptbook engine
|
|
20
21
|
*
|
|
22
|
+
* @generated
|
|
21
23
|
* @see https://github.com/webgptorg/promptbook
|
|
22
24
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-11';
|
|
24
26
|
/**
|
|
25
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
27
29
|
*/
|
|
28
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Name for the Promptbook
|
|
33
|
+
*
|
|
34
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
35
|
+
*
|
|
36
|
+
* @public exported from `@promptbook/core`
|
|
37
|
+
*/
|
|
38
|
+
var NAME = "Promptbook";
|
|
39
|
+
/**
|
|
40
|
+
* Email of the responsible person
|
|
41
|
+
*
|
|
42
|
+
* @public exported from `@promptbook/core`
|
|
43
|
+
*/
|
|
44
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
45
|
+
/**
|
|
46
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
47
|
+
*
|
|
48
|
+
* @public exported from `@promptbook/core`
|
|
49
|
+
*/
|
|
50
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
51
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
52
|
+
/**
|
|
53
|
+
* The maximum number of iterations for a loops
|
|
54
|
+
*
|
|
55
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
56
|
+
*/
|
|
57
|
+
var LOOP_LIMIT = 1000;
|
|
58
|
+
/**
|
|
59
|
+
* Strings to represent various values in the context of parameter values
|
|
60
|
+
*
|
|
61
|
+
* @public exported from `@promptbook/utils`
|
|
62
|
+
*/
|
|
63
|
+
var VALUE_STRINGS = {
|
|
64
|
+
empty: '(nothing; empty string)',
|
|
65
|
+
null: '(no value; null)',
|
|
66
|
+
undefined: '(unknown value; undefined)',
|
|
67
|
+
nan: '(not a number; NaN)',
|
|
68
|
+
infinity: '(infinity; ∞)',
|
|
69
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
70
|
+
unserializable: '(unserializable value)',
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Small number limit
|
|
74
|
+
*
|
|
75
|
+
* @public exported from `@promptbook/utils`
|
|
76
|
+
*/
|
|
77
|
+
var SMALL_NUMBER = 0.001;
|
|
78
|
+
// <- TODO: [🧜♂️]
|
|
79
|
+
/**
|
|
80
|
+
* @@@
|
|
81
|
+
*
|
|
82
|
+
* @public exported from `@promptbook/core`
|
|
83
|
+
*/
|
|
84
|
+
Object.freeze({
|
|
85
|
+
delimiter: ',',
|
|
86
|
+
quoteChar: '"',
|
|
87
|
+
newline: '\n',
|
|
88
|
+
skipEmptyLines: true,
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
92
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
93
|
+
*/
|
|
94
|
+
|
|
29
95
|
/*! *****************************************************************************
|
|
30
96
|
Copyright (c) Microsoft Corporation.
|
|
31
97
|
|
|
@@ -145,50 +211,6 @@
|
|
|
145
211
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
146
212
|
}
|
|
147
213
|
|
|
148
|
-
/**
|
|
149
|
-
* Name for the Promptbook
|
|
150
|
-
*
|
|
151
|
-
* TODO: [🗽] Unite branding and make single place for it
|
|
152
|
-
*
|
|
153
|
-
* @public exported from `@promptbook/core`
|
|
154
|
-
*/
|
|
155
|
-
var NAME = "Promptbook";
|
|
156
|
-
/**
|
|
157
|
-
* Email of the responsible person
|
|
158
|
-
*
|
|
159
|
-
* @public exported from `@promptbook/core`
|
|
160
|
-
*/
|
|
161
|
-
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
162
|
-
/**
|
|
163
|
-
* Name of the responsible person for the Promptbook on GitHub
|
|
164
|
-
*
|
|
165
|
-
* @public exported from `@promptbook/core`
|
|
166
|
-
*/
|
|
167
|
-
var ADMIN_GITHUB_NAME = 'hejny';
|
|
168
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
169
|
-
/**
|
|
170
|
-
* The maximum number of iterations for a loops
|
|
171
|
-
*
|
|
172
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
173
|
-
*/
|
|
174
|
-
var LOOP_LIMIT = 1000;
|
|
175
|
-
// <- TODO: [🧜♂️]
|
|
176
|
-
/**
|
|
177
|
-
* @@@
|
|
178
|
-
*
|
|
179
|
-
* @public exported from `@promptbook/core`
|
|
180
|
-
*/
|
|
181
|
-
Object.freeze({
|
|
182
|
-
delimiter: ',',
|
|
183
|
-
quoteChar: '"',
|
|
184
|
-
newline: '\n',
|
|
185
|
-
skipEmptyLines: true,
|
|
186
|
-
});
|
|
187
|
-
/**
|
|
188
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
189
|
-
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
214
|
/**
|
|
193
215
|
* Make error report URL for the given error
|
|
194
216
|
*
|
|
@@ -313,21 +335,44 @@
|
|
|
313
335
|
if (typeof filename !== 'string') {
|
|
314
336
|
return false;
|
|
315
337
|
}
|
|
338
|
+
if (filename.split('\n').length > 1) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
if (filename.split(' ').length >
|
|
342
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
316
345
|
var filenameSlashes = filename.split('\\').join('/');
|
|
317
346
|
// Absolute Unix path: /hello.txt
|
|
318
347
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
348
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
319
349
|
return true;
|
|
320
350
|
}
|
|
321
351
|
// Absolute Windows path: /hello.txt
|
|
322
352
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
353
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
323
354
|
return true;
|
|
324
355
|
}
|
|
325
356
|
// Relative path: ./hello.txt
|
|
326
357
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
358
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
// Allow paths like foo/hello
|
|
362
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
363
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
// Allow paths like hello.book
|
|
367
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
368
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
327
369
|
return true;
|
|
328
370
|
}
|
|
329
371
|
return false;
|
|
330
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* TODO: [🍏] Implement for MacOs
|
|
375
|
+
*/
|
|
331
376
|
|
|
332
377
|
/**
|
|
333
378
|
* Tests if given string is valid URL.
|
|
@@ -842,7 +887,7 @@
|
|
|
842
887
|
if (!(error instanceof Error)) {
|
|
843
888
|
throw error;
|
|
844
889
|
}
|
|
845
|
-
throw new ParseError(spaceTrim$1.spaceTrim(function (block) { return "\n Can not extract variables from the script\n
|
|
890
|
+
throw new ParseError(spaceTrim$1.spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
|
|
846
891
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
847
892
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
848
893
|
}
|
|
@@ -1710,6 +1755,34 @@
|
|
|
1710
1755
|
return parameterNames;
|
|
1711
1756
|
}
|
|
1712
1757
|
|
|
1758
|
+
/**
|
|
1759
|
+
* Format either small or big number
|
|
1760
|
+
*
|
|
1761
|
+
* @public exported from `@promptbook/utils`
|
|
1762
|
+
*/
|
|
1763
|
+
function numberToString(value) {
|
|
1764
|
+
if (value === 0) {
|
|
1765
|
+
return '0';
|
|
1766
|
+
}
|
|
1767
|
+
else if (Number.isNaN(value)) {
|
|
1768
|
+
return VALUE_STRINGS.nan;
|
|
1769
|
+
}
|
|
1770
|
+
else if (value === Infinity) {
|
|
1771
|
+
return VALUE_STRINGS.infinity;
|
|
1772
|
+
}
|
|
1773
|
+
else if (value === -Infinity) {
|
|
1774
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
1775
|
+
}
|
|
1776
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
1777
|
+
var factor = Math.pow(10, exponent);
|
|
1778
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
1779
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
1780
|
+
return valueRounded.toFixed(exponent);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
return value.toString();
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1713
1786
|
/**
|
|
1714
1787
|
* Freezes the given object and all its nested objects recursively
|
|
1715
1788
|
*
|
|
@@ -1838,7 +1911,7 @@
|
|
|
1838
1911
|
if (!(error instanceof Error)) {
|
|
1839
1912
|
throw error;
|
|
1840
1913
|
}
|
|
1841
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
1914
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
1842
1915
|
}
|
|
1843
1916
|
/*
|
|
1844
1917
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -1972,16 +2045,66 @@
|
|
|
1972
2045
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1973
2046
|
*/
|
|
1974
2047
|
|
|
2048
|
+
/**
|
|
2049
|
+
* Function `valueToString` will convert the given value to string
|
|
2050
|
+
* This is useful and used in the `templateParameters` function
|
|
2051
|
+
*
|
|
2052
|
+
* Note: This function is not just calling `toString` method
|
|
2053
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
2054
|
+
* See `VALUE_STRINGS`
|
|
2055
|
+
*
|
|
2056
|
+
* Note: There are 2 similar functions
|
|
2057
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2058
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2059
|
+
*
|
|
2060
|
+
* @public exported from `@promptbook/utils`
|
|
2061
|
+
*/
|
|
2062
|
+
function valueToString(value) {
|
|
2063
|
+
try {
|
|
2064
|
+
if (value === '') {
|
|
2065
|
+
return VALUE_STRINGS.empty;
|
|
2066
|
+
}
|
|
2067
|
+
else if (value === null) {
|
|
2068
|
+
return VALUE_STRINGS.null;
|
|
2069
|
+
}
|
|
2070
|
+
else if (value === undefined) {
|
|
2071
|
+
return VALUE_STRINGS.undefined;
|
|
2072
|
+
}
|
|
2073
|
+
else if (typeof value === 'string') {
|
|
2074
|
+
return value;
|
|
2075
|
+
}
|
|
2076
|
+
else if (typeof value === 'number') {
|
|
2077
|
+
return numberToString(value);
|
|
2078
|
+
}
|
|
2079
|
+
else if (value instanceof Date) {
|
|
2080
|
+
return value.toISOString();
|
|
2081
|
+
}
|
|
2082
|
+
else {
|
|
2083
|
+
return JSON.stringify(value);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
catch (error) {
|
|
2087
|
+
if (!(error instanceof Error)) {
|
|
2088
|
+
throw error;
|
|
2089
|
+
}
|
|
2090
|
+
console.error(error);
|
|
2091
|
+
return VALUE_STRINGS.unserializable;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
|
|
1975
2095
|
/**
|
|
1976
2096
|
* Replaces parameters in template with values from parameters object
|
|
1977
2097
|
*
|
|
2098
|
+
* Note: This function is not places strings into string,
|
|
2099
|
+
* It's more complex and can handle this operation specifically for LLM models
|
|
2100
|
+
*
|
|
1978
2101
|
* @param template the template with parameters in {curly} braces
|
|
1979
2102
|
* @param parameters the object with parameters
|
|
1980
2103
|
* @returns the template with replaced parameters
|
|
1981
2104
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
1982
2105
|
* @public exported from `@promptbook/utils`
|
|
1983
2106
|
*/
|
|
1984
|
-
function
|
|
2107
|
+
function templateParameters(template, parameters) {
|
|
1985
2108
|
var e_1, _a;
|
|
1986
2109
|
try {
|
|
1987
2110
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -2007,7 +2130,7 @@
|
|
|
2007
2130
|
var loopLimit = LOOP_LIMIT;
|
|
2008
2131
|
var _loop_1 = function () {
|
|
2009
2132
|
if (loopLimit-- < 0) {
|
|
2010
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
2133
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
2011
2134
|
}
|
|
2012
2135
|
var precol = match.groups.precol;
|
|
2013
2136
|
var parameterName = match.groups.parameterName;
|
|
@@ -2024,7 +2147,7 @@
|
|
|
2024
2147
|
if (parameterValue === undefined) {
|
|
2025
2148
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
2026
2149
|
}
|
|
2027
|
-
parameterValue = parameterValue
|
|
2150
|
+
parameterValue = valueToString(parameterValue);
|
|
2028
2151
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2029
2152
|
parameterValue = parameterValue
|
|
2030
2153
|
.split('\n')
|
|
@@ -2163,7 +2286,7 @@
|
|
|
2163
2286
|
*/
|
|
2164
2287
|
function clonePipeline(pipeline) {
|
|
2165
2288
|
// Note: Not using spread operator (...) because @@@
|
|
2166
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
2289
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations, sources = pipeline.sources;
|
|
2167
2290
|
return {
|
|
2168
2291
|
pipelineUrl: pipelineUrl,
|
|
2169
2292
|
sourceFile: sourceFile,
|
|
@@ -2177,6 +2300,7 @@
|
|
|
2177
2300
|
knowledgePieces: knowledgePieces,
|
|
2178
2301
|
personas: personas,
|
|
2179
2302
|
preparations: preparations,
|
|
2303
|
+
sources: sources,
|
|
2180
2304
|
};
|
|
2181
2305
|
}
|
|
2182
2306
|
/**
|
|
@@ -2450,6 +2574,25 @@
|
|
|
2450
2574
|
return /^.+@.+\..+$/.test(email);
|
|
2451
2575
|
}
|
|
2452
2576
|
|
|
2577
|
+
/**
|
|
2578
|
+
* Determines if the given path is a root path.
|
|
2579
|
+
*
|
|
2580
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
2581
|
+
* @public exported from `@promptbook/utils`
|
|
2582
|
+
*/
|
|
2583
|
+
function isPathRoot(value) {
|
|
2584
|
+
if (value === '/') {
|
|
2585
|
+
return true;
|
|
2586
|
+
}
|
|
2587
|
+
if (/^[A-Z]:\\$/i.test(value)) {
|
|
2588
|
+
return true;
|
|
2589
|
+
}
|
|
2590
|
+
return false;
|
|
2591
|
+
}
|
|
2592
|
+
/**
|
|
2593
|
+
* TODO: [🍏] Make for MacOS paths
|
|
2594
|
+
*/
|
|
2595
|
+
|
|
2453
2596
|
/**
|
|
2454
2597
|
* @@@
|
|
2455
2598
|
*
|
|
@@ -2573,9 +2716,6 @@
|
|
|
2573
2716
|
if (!url.startsWith('https://')) {
|
|
2574
2717
|
return false;
|
|
2575
2718
|
}
|
|
2576
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
2577
|
-
return false;
|
|
2578
|
-
}
|
|
2579
2719
|
if (url.includes('#')) {
|
|
2580
2720
|
// TODO: [🐠]
|
|
2581
2721
|
return false;
|
|
@@ -2614,6 +2754,8 @@
|
|
|
2614
2754
|
exports.DIACRITIC_VARIANTS_LETTERS = DIACRITIC_VARIANTS_LETTERS;
|
|
2615
2755
|
exports.LINES_PER_STANDARD_PAGE = LINES_PER_STANDARD_PAGE;
|
|
2616
2756
|
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
2757
|
+
exports.SMALL_NUMBER = SMALL_NUMBER;
|
|
2758
|
+
exports.VALUE_STRINGS = VALUE_STRINGS;
|
|
2617
2759
|
exports.capitalize = capitalize;
|
|
2618
2760
|
exports.checkSerializableAsJson = checkSerializableAsJson;
|
|
2619
2761
|
exports.clonePipeline = clonePipeline;
|
|
@@ -2633,6 +2775,7 @@
|
|
|
2633
2775
|
exports.forEachAsync = forEachAsync;
|
|
2634
2776
|
exports.intersection = intersection;
|
|
2635
2777
|
exports.isHostnameOnPrivateNetwork = isHostnameOnPrivateNetwork;
|
|
2778
|
+
exports.isPathRoot = isPathRoot;
|
|
2636
2779
|
exports.isSerializableAsJson = isSerializableAsJson;
|
|
2637
2780
|
exports.isUrlOnPrivateNetwork = isUrlOnPrivateNetwork;
|
|
2638
2781
|
exports.isValidEmail = isValidEmail;
|
|
@@ -2653,6 +2796,7 @@
|
|
|
2653
2796
|
exports.normalizeTo_camelCase = normalizeTo_camelCase;
|
|
2654
2797
|
exports.normalizeTo_snake_case = normalizeTo_snake_case;
|
|
2655
2798
|
exports.normalizeWhitespaces = normalizeWhitespaces;
|
|
2799
|
+
exports.numberToString = numberToString;
|
|
2656
2800
|
exports.orderJson = orderJson;
|
|
2657
2801
|
exports.parseKeywords = parseKeywords;
|
|
2658
2802
|
exports.parseKeywordsFromString = parseKeywordsFromString;
|
|
@@ -2661,16 +2805,17 @@
|
|
|
2661
2805
|
exports.removeEmojis = removeEmojis;
|
|
2662
2806
|
exports.removeQuotes = removeQuotes;
|
|
2663
2807
|
exports.renderPromptbookMermaid = renderPromptbookMermaid;
|
|
2664
|
-
exports.replaceParameters = replaceParameters;
|
|
2665
2808
|
exports.searchKeywords = searchKeywords;
|
|
2666
2809
|
exports.serializeError = serializeError;
|
|
2667
2810
|
exports.spaceTrim = spaceTrim;
|
|
2668
2811
|
exports.splitIntoSentences = splitIntoSentences;
|
|
2812
|
+
exports.templateParameters = templateParameters;
|
|
2669
2813
|
exports.titleToName = titleToName;
|
|
2670
2814
|
exports.trimCodeBlock = trimCodeBlock;
|
|
2671
2815
|
exports.trimEndOfCodeBlock = trimEndOfCodeBlock;
|
|
2672
2816
|
exports.union = union;
|
|
2673
2817
|
exports.unwrapResult = unwrapResult;
|
|
2818
|
+
exports.valueToString = valueToString;
|
|
2674
2819
|
|
|
2675
2820
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2676
2821
|
|