@promptbook/core 0.80.0-1 → 0.81.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.
- package/README.md +2 -0
- package/esm/index.es.js +39 -184
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +0 -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 +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
- 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/expectations/drafts/isDomainNameFree.d.ts +2 -1
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
- package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +42 -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/getBookTemplate.d.ts +12 -0
- package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +1 -1
- package/package.json +1 -2
- package/umd/index.umd.js +38 -186
- package/umd/index.umd.js.map +1 -1
- /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/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
|
@@ -34,9 +34,6 @@ import { pipelineJsonToString } from '../conversion/pipelineJsonToString';
|
|
|
34
34
|
import { precompilePipeline } from '../conversion/precompilePipeline';
|
|
35
35
|
import { prettifyPipelineString } from '../conversion/prettify/prettifyPipelineString';
|
|
36
36
|
import { extractParameterNamesFromTask } from '../conversion/utils/extractParameterNamesFromTask';
|
|
37
|
-
import { removePipelineCommand } from '../conversion/utils/removePipelineCommand';
|
|
38
|
-
import { renamePipelineParameter } from '../conversion/utils/renamePipelineParameter';
|
|
39
|
-
import { stringifyPipelineJson } from '../conversion/utils/stringifyPipelineJson';
|
|
40
37
|
import { validatePipeline } from '../conversion/validation/validatePipeline';
|
|
41
38
|
import { CallbackInterfaceTools } from '../dialogs/callback/CallbackInterfaceTools';
|
|
42
39
|
import type { CallbackInterfaceToolsOptions } from '../dialogs/callback/CallbackInterfaceToolsOptions';
|
|
@@ -155,9 +152,6 @@ export { pipelineJsonToString };
|
|
|
155
152
|
export { precompilePipeline };
|
|
156
153
|
export { prettifyPipelineString };
|
|
157
154
|
export { extractParameterNamesFromTask };
|
|
158
|
-
export { removePipelineCommand };
|
|
159
|
-
export { renamePipelineParameter };
|
|
160
|
-
export { stringifyPipelineJson };
|
|
161
155
|
export { validatePipeline };
|
|
162
156
|
export { CallbackInterfaceTools };
|
|
163
157
|
export type { CallbackInterfaceToolsOptions };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
|
|
2
|
+
import type { PipelineEditableSerialized } from '../utils/editable/types/PipelineEditableSerialized';
|
|
3
|
+
import { removePipelineCommand } from '../utils/editable/utils/removePipelineCommand';
|
|
4
|
+
import { renamePipelineParameter } from '../utils/editable/utils/renamePipelineParameter';
|
|
5
|
+
import { stringifyPipelineJson } from '../utils/editable/utils/stringifyPipelineJson';
|
|
6
|
+
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
|
7
|
+
export type { PipelineEditableSerialized };
|
|
8
|
+
export { removePipelineCommand };
|
|
9
|
+
export { renamePipelineParameter };
|
|
10
|
+
export { stringifyPipelineJson };
|
|
@@ -30,6 +30,7 @@ import type { LlmExecutionTools } from '../execution/LlmExecutionTools';
|
|
|
30
30
|
import type { LlmExecutionToolsConstructor } from '../execution/LlmExecutionToolsConstructor';
|
|
31
31
|
import type { PipelineExecutor } from '../execution/PipelineExecutor';
|
|
32
32
|
import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
|
|
33
|
+
import type { PromptbookFetch } from '../execution/PromptbookFetch';
|
|
33
34
|
import type { PromptResult } from '../execution/PromptResult';
|
|
34
35
|
import type { CompletionPromptResult } from '../execution/PromptResult';
|
|
35
36
|
import type { ChatPromptResult } from '../execution/PromptResult';
|
|
@@ -241,6 +242,7 @@ import type { number_gigabytes } from '../types/typeAliases';
|
|
|
241
242
|
import type { number_terabytes } from '../types/typeAliases';
|
|
242
243
|
import type { Registered } from '../utils/$Register';
|
|
243
244
|
import type { Registration } from '../utils/$Register';
|
|
245
|
+
import type { PipelineEditableSerialized } from '../utils/editable/types/PipelineEditableSerialized';
|
|
244
246
|
import type { ExecCommandOptions } from '../utils/execCommand/ExecCommandOptions';
|
|
245
247
|
import type { ExecCommandOptionsAdvanced } from '../utils/execCommand/ExecCommandOptions';
|
|
246
248
|
import type { FromtoItems } from '../utils/FromtoItems';
|
|
@@ -292,6 +294,7 @@ export type { LlmExecutionTools };
|
|
|
292
294
|
export type { LlmExecutionToolsConstructor };
|
|
293
295
|
export type { PipelineExecutor };
|
|
294
296
|
export type { PipelineExecutorResult };
|
|
297
|
+
export type { PromptbookFetch };
|
|
295
298
|
export type { PromptResult };
|
|
296
299
|
export type { CompletionPromptResult };
|
|
297
300
|
export type { ChatPromptResult };
|
|
@@ -503,6 +506,7 @@ export type { number_gigabytes };
|
|
|
503
506
|
export type { number_terabytes };
|
|
504
507
|
export type { Registered };
|
|
505
508
|
export type { Registration };
|
|
509
|
+
export type { PipelineEditableSerialized };
|
|
506
510
|
export type { ExecCommandOptions };
|
|
507
511
|
export type { ExecCommandOptionsAdvanced };
|
|
508
512
|
export type { FromtoItems };
|
|
@@ -46,7 +46,7 @@ import { searchKeywords } from '../utils/normalization/searchKeywords';
|
|
|
46
46
|
import { titleToName } from '../utils/normalization/titleToName';
|
|
47
47
|
import { spaceTrim } from '../utils/organization/spaceTrim';
|
|
48
48
|
import { extractParameterNames } from '../utils/parameters/extractParameterNames';
|
|
49
|
-
import {
|
|
49
|
+
import { templateParameters } from '../utils/parameters/templateParameters';
|
|
50
50
|
import { parseNumber } from '../utils/parseNumber';
|
|
51
51
|
import { $randomSeed } from '../utils/random/$randomSeed';
|
|
52
52
|
import { removeEmojis } from '../utils/removeEmojis';
|
|
@@ -121,7 +121,7 @@ export { searchKeywords };
|
|
|
121
121
|
export { titleToName };
|
|
122
122
|
export { spaceTrim };
|
|
123
123
|
export { extractParameterNames };
|
|
124
|
-
export {
|
|
124
|
+
export { templateParameters };
|
|
125
125
|
export { parseNumber };
|
|
126
126
|
export { $randomSeed };
|
|
127
127
|
export { removeEmojis };
|
|
@@ -3,6 +3,7 @@ import type { Arrayable } from '../types/Arrayable';
|
|
|
3
3
|
import type { Executables } from './Executables';
|
|
4
4
|
import type { FilesystemTools } from './FilesystemTools';
|
|
5
5
|
import type { LlmExecutionTools } from './LlmExecutionTools';
|
|
6
|
+
import type { PromptbookFetch } from './PromptbookFetch';
|
|
6
7
|
import type { ScriptExecutionTools } from './ScriptExecutionTools';
|
|
7
8
|
import type { UserInterfaceTools } from './UserInterfaceTools';
|
|
8
9
|
/**
|
|
@@ -27,6 +28,12 @@ export type ExecutionTools = {
|
|
|
27
28
|
* @default undefined - If not provided, no filesystem operations will be possible
|
|
28
29
|
*/
|
|
29
30
|
readonly fs?: FilesystemTools;
|
|
31
|
+
/**
|
|
32
|
+
* Fetch function for fetching resources
|
|
33
|
+
*
|
|
34
|
+
* @default `fetch` - If not provided, the built-in `fetch' function is used with a lightweight error handling wrapper.
|
|
35
|
+
*/
|
|
36
|
+
readonly fetch?: PromptbookFetch;
|
|
30
37
|
/**
|
|
31
38
|
* Scrapers for extracting knowledge from external sources
|
|
32
39
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { PromptbookFetch } from '../../execution/PromptbookFetch';
|
|
1
2
|
import type { string_name } from '../../types/typeAliases';
|
|
2
3
|
/**
|
|
3
4
|
* @private still in development
|
|
4
5
|
*/
|
|
5
|
-
export declare function isDomainNameFree(name: string_name): Promise<boolean>;
|
|
6
|
+
export declare function isDomainNameFree(name: string_name, fetch: PromptbookFetch): Promise<boolean>;
|
|
6
7
|
/**
|
|
7
8
|
* TODO: [🍓][🧠] Test and implement `isDomainNameFree`
|
|
8
9
|
* TODO: Export via some (and probably new) NPM package
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { PromptbookFetch } from '../../execution/PromptbookFetch';
|
|
1
2
|
import type { string_name } from '../../types/typeAliases';
|
|
2
3
|
/**
|
|
3
4
|
* @private still in development
|
|
4
5
|
*/
|
|
5
|
-
export declare function isGithubNameFree(name: string_name): Promise<boolean>;
|
|
6
|
+
export declare function isGithubNameFree(name: string_name, fetch: PromptbookFetch): Promise<boolean>;
|
|
6
7
|
/**
|
|
7
8
|
* TODO: [🍓][🧠] Test and implement `isGithubNameFree`
|
|
8
9
|
* TODO: Export via some (and probably new) NPM package
|
|
@@ -8,4 +8,4 @@ import type { ScraperSourceHandler } from '../Scraper';
|
|
|
8
8
|
*
|
|
9
9
|
* @public exported from `@promptbook/core`
|
|
10
10
|
*/
|
|
11
|
-
export declare function makeKnowledgeSourceHandler(knowledgeSource: SetOptional<KnowledgeSourceJson, 'name'>, tools: Pick<ExecutionTools, 'fs'>, options?: Pick<PrepareAndScrapeOptions, 'rootDirname' | 'isVerbose'>): Promise<ScraperSourceHandler>;
|
|
11
|
+
export declare function makeKnowledgeSourceHandler(knowledgeSource: SetOptional<KnowledgeSourceJson, 'name'>, tools: Pick<ExecutionTools, 'fs' | 'fetch'>, options?: Pick<PrepareAndScrapeOptions, 'rootDirname' | 'isVerbose'>): Promise<ScraperSourceHandler>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PromptbookFetch } from '../../../execution/PromptbookFetch';
|
|
2
|
+
/**
|
|
3
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
4
|
+
*
|
|
5
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
6
|
+
*/
|
|
7
|
+
export declare const scraperFetch: PromptbookFetch;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ErrorJson } from '../../../errors/utils/ErrorJson';
|
|
2
|
+
import type { PipelineJson } from '../../../pipeline/PipelineJson/PipelineJson';
|
|
3
|
+
import type { string_date_iso8601 } from '../../../types/typeAliases';
|
|
4
|
+
import type { string_pipeline_url } from '../../../types/typeAliases';
|
|
5
|
+
import type { PipelineString } from '../../../pipeline/PipelineString';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a single pipeline in PromptbookStudio
|
|
8
|
+
*
|
|
9
|
+
* This is simple extension of PipelineJson with additional metadata
|
|
10
|
+
* Note: There are two similar entities:
|
|
11
|
+
* 1) Type (interface) `PipelineEditableSerialized` which represents just data in database
|
|
12
|
+
* 2) Class `PipelineEditable` which implements `PipelineEditableSerialized` and adds error handling and editing capabilities
|
|
13
|
+
*
|
|
14
|
+
* @public exported from `@promptbook/editable`
|
|
15
|
+
*/
|
|
16
|
+
export type PipelineEditableSerialized = PipelineJson & {
|
|
17
|
+
/**
|
|
18
|
+
* When was the pipeline created
|
|
19
|
+
*/
|
|
20
|
+
readonly createdAt: string_date_iso8601;
|
|
21
|
+
/**
|
|
22
|
+
* When was the pipeline last modified
|
|
23
|
+
*/
|
|
24
|
+
readonly updatedAt: string_date_iso8601 | null;
|
|
25
|
+
/**
|
|
26
|
+
* Unique identifier of the pipeline
|
|
27
|
+
*
|
|
28
|
+
* Note: In PromptbookStudio it is required
|
|
29
|
+
*/
|
|
30
|
+
readonly pipelineUrl: string_pipeline_url;
|
|
31
|
+
/**
|
|
32
|
+
* Backup of the pipeline string
|
|
33
|
+
*
|
|
34
|
+
* Note: This is present ONLY if pipelineString can not be automatically converted into json (i.e. compilePipeline throws an error)
|
|
35
|
+
* In other words, this is just a BACKUP of pipeline which will be deleted whener pipeline is valid again
|
|
36
|
+
*/
|
|
37
|
+
readonly pipelineString: PipelineString | string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Known errors to transfer to new PipelineEditable
|
|
40
|
+
*/
|
|
41
|
+
readonly knownErrors: Array<ErrorJson>;
|
|
42
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CommandType } from '
|
|
2
|
-
import type { PipelineString } from '
|
|
1
|
+
import type { CommandType } from '../../../commands/_common/types/CommandType';
|
|
2
|
+
import type { PipelineString } from '../../../pipeline/PipelineString';
|
|
3
3
|
/**
|
|
4
4
|
* Options for `removePipelineCommand`
|
|
5
5
|
*/
|
|
@@ -16,7 +16,7 @@ type RemovePipelineCommandOptions = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Function `removePipelineCommand` will remove one command from pipeline string
|
|
18
18
|
*
|
|
19
|
-
* @public exported from `@promptbook/
|
|
19
|
+
* @public exported from `@promptbook/editable`
|
|
20
20
|
*/
|
|
21
21
|
export declare function removePipelineCommand(options: RemovePipelineCommandOptions): PipelineString;
|
|
22
22
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PipelineJson } from '
|
|
2
|
-
import type { string_name } from '
|
|
1
|
+
import type { PipelineJson } from '../../../pipeline/PipelineJson/PipelineJson';
|
|
2
|
+
import type { string_name } from '../../../types/typeAliases';
|
|
3
3
|
type RenameParameterOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Pipeline to search and replace for parameters
|
|
@@ -20,7 +20,7 @@ type RenameParameterOptions = {
|
|
|
20
20
|
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
21
21
|
*
|
|
22
22
|
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
23
|
-
* @public exported from `@promptbook/
|
|
23
|
+
* @public exported from `@promptbook/editable`
|
|
24
24
|
*/
|
|
25
25
|
export declare function renamePipelineParameter(options: RenameParameterOptions): PipelineJson;
|
|
26
26
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { string_json } from '
|
|
1
|
+
import type { string_json } from '../../../types/typeAliases';
|
|
2
2
|
/**
|
|
3
3
|
* Stringify the PipelineJson with proper formatting
|
|
4
4
|
*
|
|
5
5
|
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
6
6
|
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
7
7
|
*
|
|
8
|
-
* @public exported from `@promptbook/
|
|
8
|
+
* @public exported from `@promptbook/editable`
|
|
9
9
|
*/
|
|
10
10
|
export declare function stringifyPipelineJson<TType>(pipeline: TType): string_json<TType>;
|
|
11
11
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
|
|
2
|
+
import type { string_formfactor_name } from '../formfactors/_common/string_formfactor_name';
|
|
3
|
+
/**
|
|
4
|
+
* Get template for new book
|
|
5
|
+
*
|
|
6
|
+
* @public exported from `@promptbook/templates`
|
|
7
|
+
*/
|
|
8
|
+
export declare function getBookTemplate(formfactorName: string_formfactor_name): PipelineJson | null;
|
|
9
|
+
/**
|
|
10
|
+
* TODO: [🧠] Which is the best place for this function
|
|
11
|
+
* TODO: `book string template notation
|
|
12
|
+
*/
|
|
@@ -9,4 +9,4 @@ import type { string_template } from '../../types/typeAliases';
|
|
|
9
9
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
10
10
|
* @public exported from `@promptbook/utils`
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function templateParameters(template: string_template, parameters: Parameters): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.0-5",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"--note-0": " <- [🐊]",
|
|
6
6
|
"private": false,
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
"papaparse": "5.4.1",
|
|
61
61
|
"prettier": "2.8.1",
|
|
62
62
|
"spacetrim": "0.11.59",
|
|
63
|
-
"type-fest": "4.5.0",
|
|
64
63
|
"waitasecond": "1.11.83"
|
|
65
64
|
}
|
|
66
65
|
}
|
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.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
|
|
@@ -3454,7 +3454,7 @@
|
|
|
3454
3454
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
3455
3455
|
* @public exported from `@promptbook/utils`
|
|
3456
3456
|
*/
|
|
3457
|
-
function
|
|
3457
|
+
function templateParameters(template, parameters) {
|
|
3458
3458
|
var e_1, _a;
|
|
3459
3459
|
try {
|
|
3460
3460
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -3480,7 +3480,7 @@
|
|
|
3480
3480
|
var loopLimit = LOOP_LIMIT;
|
|
3481
3481
|
var _loop_1 = function () {
|
|
3482
3482
|
if (loopLimit-- < 0) {
|
|
3483
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
3483
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
3484
3484
|
}
|
|
3485
3485
|
var precol = match.groups.precol;
|
|
3486
3486
|
var parameterName = match.groups.parameterName;
|
|
@@ -4015,7 +4015,7 @@
|
|
|
4015
4015
|
}
|
|
4016
4016
|
return [3 /*break*/, 24];
|
|
4017
4017
|
case 2:
|
|
4018
|
-
$ongoingTaskResult.$resultString =
|
|
4018
|
+
$ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
|
|
4019
4019
|
return [3 /*break*/, 25];
|
|
4020
4020
|
case 3:
|
|
4021
4021
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
@@ -4138,8 +4138,8 @@
|
|
|
4138
4138
|
_j = $ongoingTaskResult;
|
|
4139
4139
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
4140
4140
|
promptTitle: task.title,
|
|
4141
|
-
promptMessage:
|
|
4142
|
-
defaultValue:
|
|
4141
|
+
promptMessage: templateParameters(task.description || '', parameters),
|
|
4142
|
+
defaultValue: templateParameters(preparedContent, parameters),
|
|
4143
4143
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4144
4144
|
placeholder: undefined,
|
|
4145
4145
|
priority: priority,
|
|
@@ -4263,7 +4263,7 @@
|
|
|
4263
4263
|
if (!isJokerAttempt &&
|
|
4264
4264
|
task.taskType === 'PROMPT_TASK' &&
|
|
4265
4265
|
$ongoingTaskResult.$prompt
|
|
4266
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in
|
|
4266
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
|
|
4267
4267
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4268
4268
|
) {
|
|
4269
4269
|
// TODO: [🧠] Maybe put other taskTypes into report
|
|
@@ -5596,6 +5596,30 @@
|
|
|
5596
5596
|
return false;
|
|
5597
5597
|
}
|
|
5598
5598
|
|
|
5599
|
+
/**
|
|
5600
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5601
|
+
*
|
|
5602
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
5603
|
+
*/
|
|
5604
|
+
var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5605
|
+
var error_1;
|
|
5606
|
+
return __generator(this, function (_a) {
|
|
5607
|
+
switch (_a.label) {
|
|
5608
|
+
case 0:
|
|
5609
|
+
_a.trys.push([0, 2, , 3]);
|
|
5610
|
+
return [4 /*yield*/, fetch(url, init)];
|
|
5611
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5612
|
+
case 2:
|
|
5613
|
+
error_1 = _a.sent();
|
|
5614
|
+
if (!(error_1 instanceof Error)) {
|
|
5615
|
+
throw error_1;
|
|
5616
|
+
}
|
|
5617
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
|
|
5618
|
+
case 3: return [2 /*return*/];
|
|
5619
|
+
}
|
|
5620
|
+
});
|
|
5621
|
+
}); };
|
|
5622
|
+
|
|
5599
5623
|
/**
|
|
5600
5624
|
* @@@
|
|
5601
5625
|
*
|
|
@@ -5604,13 +5628,14 @@
|
|
|
5604
5628
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5605
5629
|
var _a;
|
|
5606
5630
|
return __awaiter(this, void 0, void 0, function () {
|
|
5607
|
-
var sourceContent, name,
|
|
5608
|
-
return __generator(this, function (
|
|
5609
|
-
switch (
|
|
5631
|
+
var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
5632
|
+
return __generator(this, function (_f) {
|
|
5633
|
+
switch (_f.label) {
|
|
5610
5634
|
case 0:
|
|
5635
|
+
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
5611
5636
|
sourceContent = knowledgeSource.sourceContent;
|
|
5612
5637
|
name = knowledgeSource.name;
|
|
5613
|
-
|
|
5638
|
+
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
5614
5639
|
if (!name) {
|
|
5615
5640
|
name = sourceContentToName(sourceContent);
|
|
5616
5641
|
}
|
|
@@ -5618,7 +5643,7 @@
|
|
|
5618
5643
|
url = sourceContent;
|
|
5619
5644
|
return [4 /*yield*/, fetch(url)];
|
|
5620
5645
|
case 1:
|
|
5621
|
-
response_1 =
|
|
5646
|
+
response_1 = _f.sent();
|
|
5622
5647
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5623
5648
|
return [2 /*return*/, {
|
|
5624
5649
|
source: name,
|
|
@@ -5675,7 +5700,7 @@
|
|
|
5675
5700
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
5676
5701
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5677
5702
|
case 3:
|
|
5678
|
-
if (!(
|
|
5703
|
+
if (!(_f.sent())) {
|
|
5679
5704
|
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
5680
5705
|
}
|
|
5681
5706
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -9583,176 +9608,6 @@
|
|
|
9583
9608
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
9584
9609
|
*/
|
|
9585
9610
|
|
|
9586
|
-
/**
|
|
9587
|
-
* Function `removePipelineCommand` will remove one command from pipeline string
|
|
9588
|
-
*
|
|
9589
|
-
* @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
|
|
9590
|
-
*/
|
|
9591
|
-
function removePipelineCommand(options) {
|
|
9592
|
-
var e_1, _a;
|
|
9593
|
-
var command = options.command, pipeline = options.pipeline;
|
|
9594
|
-
var lines = pipeline.split('\n');
|
|
9595
|
-
// TODO: [🧽] DRY
|
|
9596
|
-
var currentType = 'MARKDOWN';
|
|
9597
|
-
var newLines = [];
|
|
9598
|
-
try {
|
|
9599
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
9600
|
-
var line = lines_1_1.value;
|
|
9601
|
-
if (currentType === 'MARKDOWN') {
|
|
9602
|
-
if (line.startsWith('```')) {
|
|
9603
|
-
currentType = 'CODE_BLOCK';
|
|
9604
|
-
}
|
|
9605
|
-
else if (line.includes('<!--')) {
|
|
9606
|
-
currentType = 'COMMENT';
|
|
9607
|
-
}
|
|
9608
|
-
}
|
|
9609
|
-
else if (currentType === 'CODE_BLOCK') {
|
|
9610
|
-
if (line.startsWith('```')) {
|
|
9611
|
-
currentType = 'MARKDOWN';
|
|
9612
|
-
}
|
|
9613
|
-
}
|
|
9614
|
-
else if (currentType === 'COMMENT') {
|
|
9615
|
-
if (line.includes('-->')) {
|
|
9616
|
-
currentType = 'MARKDOWN';
|
|
9617
|
-
}
|
|
9618
|
-
}
|
|
9619
|
-
if (currentType === 'MARKDOWN' && /^(-|\d\))/m.test(line) && line.toUpperCase().includes(command)) {
|
|
9620
|
-
continue;
|
|
9621
|
-
}
|
|
9622
|
-
newLines.push(line);
|
|
9623
|
-
}
|
|
9624
|
-
}
|
|
9625
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9626
|
-
finally {
|
|
9627
|
-
try {
|
|
9628
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
9629
|
-
}
|
|
9630
|
-
finally { if (e_1) throw e_1.error; }
|
|
9631
|
-
}
|
|
9632
|
-
var newPipeline = spaceTrim__default["default"](newLines.join('\n'));
|
|
9633
|
-
return newPipeline;
|
|
9634
|
-
}
|
|
9635
|
-
|
|
9636
|
-
/**
|
|
9637
|
-
* Function `renamePipelineParameter` will find all usable parameters for given task
|
|
9638
|
-
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
9639
|
-
*
|
|
9640
|
-
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
9641
|
-
* @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
|
|
9642
|
-
*/
|
|
9643
|
-
function renamePipelineParameter(options) {
|
|
9644
|
-
var e_1, _a, e_2, _b;
|
|
9645
|
-
var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
|
|
9646
|
-
if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
|
|
9647
|
-
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
9648
|
-
}
|
|
9649
|
-
var renamedPipeline = __assign(__assign({}, pipeline), {
|
|
9650
|
-
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
9651
|
-
parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
|
|
9652
|
-
try {
|
|
9653
|
-
for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
9654
|
-
var parameter = _d.value;
|
|
9655
|
-
if (parameter.name !== oldParameterName) {
|
|
9656
|
-
continue;
|
|
9657
|
-
}
|
|
9658
|
-
parameter.name = newParameterName;
|
|
9659
|
-
}
|
|
9660
|
-
}
|
|
9661
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9662
|
-
finally {
|
|
9663
|
-
try {
|
|
9664
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
9665
|
-
}
|
|
9666
|
-
finally { if (e_1) throw e_1.error; }
|
|
9667
|
-
}
|
|
9668
|
-
try {
|
|
9669
|
-
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
9670
|
-
var task = _f.value;
|
|
9671
|
-
if (task.resultingParameterName === oldParameterName) {
|
|
9672
|
-
task.resultingParameterName = newParameterName;
|
|
9673
|
-
}
|
|
9674
|
-
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
9675
|
-
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
9676
|
-
});
|
|
9677
|
-
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9678
|
-
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9679
|
-
task.description =
|
|
9680
|
-
task.description === undefined
|
|
9681
|
-
? undefined
|
|
9682
|
-
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9683
|
-
}
|
|
9684
|
-
}
|
|
9685
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
9686
|
-
finally {
|
|
9687
|
-
try {
|
|
9688
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
9689
|
-
}
|
|
9690
|
-
finally { if (e_2) throw e_2.error; }
|
|
9691
|
-
}
|
|
9692
|
-
return renamedPipeline;
|
|
9693
|
-
}
|
|
9694
|
-
|
|
9695
|
-
// <- TODO: !!!!!!! Auto convert to type `import { ... } from 'type-fest';`
|
|
9696
|
-
/**
|
|
9697
|
-
* Tests if the value is [🚉] serializable as JSON
|
|
9698
|
-
*
|
|
9699
|
-
* - Almost all primitives are serializable BUT:
|
|
9700
|
-
* - `undefined` is not serializable
|
|
9701
|
-
* - `NaN` is not serializable
|
|
9702
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
9703
|
-
* - Functions are not serializable
|
|
9704
|
-
* - Circular references are not serializable
|
|
9705
|
-
* - `Date` objects are not serializable
|
|
9706
|
-
* - `Map` and `Set` objects are not serializable
|
|
9707
|
-
* - `RegExp` objects are not serializable
|
|
9708
|
-
* - `Error` objects are not serializable
|
|
9709
|
-
* - `Symbol` objects are not serializable
|
|
9710
|
-
* - And much more...
|
|
9711
|
-
*
|
|
9712
|
-
*
|
|
9713
|
-
* @public exported from `@promptbook/utils`
|
|
9714
|
-
*/
|
|
9715
|
-
function isSerializableAsJson(value) {
|
|
9716
|
-
try {
|
|
9717
|
-
checkSerializableAsJson({ value: value });
|
|
9718
|
-
return true;
|
|
9719
|
-
}
|
|
9720
|
-
catch (error) {
|
|
9721
|
-
return false;
|
|
9722
|
-
}
|
|
9723
|
-
}
|
|
9724
|
-
/**
|
|
9725
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
9726
|
-
* TODO: [🧠][💺] Can be done this on type-level?
|
|
9727
|
-
*/
|
|
9728
|
-
|
|
9729
|
-
/**
|
|
9730
|
-
* Stringify the PipelineJson with proper formatting
|
|
9731
|
-
*
|
|
9732
|
-
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
9733
|
-
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
9734
|
-
*
|
|
9735
|
-
* @public exported from `@promptbook/core`
|
|
9736
|
-
*/
|
|
9737
|
-
function stringifyPipelineJson(pipeline) {
|
|
9738
|
-
if (!isSerializableAsJson(pipeline)) {
|
|
9739
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
|
|
9740
|
-
}
|
|
9741
|
-
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
9742
|
-
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
9743
|
-
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
9744
|
-
}
|
|
9745
|
-
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
9746
|
-
pipelineJsonStringified += '\n';
|
|
9747
|
-
return pipelineJsonStringified;
|
|
9748
|
-
}
|
|
9749
|
-
/**
|
|
9750
|
-
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/examples/mixed-knowledge.book.md
|
|
9751
|
-
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
9752
|
-
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
9753
|
-
* TODO: [🍙] Make some standard order of json properties
|
|
9754
|
-
*/
|
|
9755
|
-
|
|
9756
9611
|
/**
|
|
9757
9612
|
* Delagates the user interaction to a async callback function
|
|
9758
9613
|
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
@@ -11244,9 +11099,6 @@
|
|
|
11244
11099
|
exports.preparePipeline = preparePipeline;
|
|
11245
11100
|
exports.prepareTasks = prepareTasks;
|
|
11246
11101
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
11247
|
-
exports.removePipelineCommand = removePipelineCommand;
|
|
11248
|
-
exports.renamePipelineParameter = renamePipelineParameter;
|
|
11249
|
-
exports.stringifyPipelineJson = stringifyPipelineJson;
|
|
11250
11102
|
exports.unpreparePipeline = unpreparePipeline;
|
|
11251
11103
|
exports.usageToHuman = usageToHuman;
|
|
11252
11104
|
exports.usageToWorktime = usageToWorktime;
|