@promptbook/core 0.71.0-13 → 0.71.0-14
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/esm/index.es.js +31 -46
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -2
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -1
- package/esm/typings/src/execution/ExecutionTools.d.ts +12 -2
- package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
- package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +1 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +2 -4
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +3 -1
- package/esm/typings/src/utils/files/{$isDirectoryExisting.d.ts → isDirectoryExisting.d.ts} +3 -4
- package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
- package/esm/typings/src/utils/files/{$listAllFiles.d.ts → listAllFiles.d.ts} +3 -4
- package/package.json +1 -1
- package/umd/index.umd.js +30 -45
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/files/$isFileExisting.d.ts +0 -14
- /package/esm/typings/src/utils/files/{$isDirectoryExisting.test.d.ts → isDirectoryExisting.test.d.ts} +0 -0
- /package/esm/typings/src/utils/files/{$isFileExisting.test.d.ts → isFileExisting.test.d.ts} +0 -0
- /package/esm/typings/src/utils/files/{$listAllFiles.test.d.ts → listAllFiles.test.d.ts} +0 -0
|
@@ -3,6 +3,7 @@ import { createCollectionFromDirectory } from '../collection/constructors/create
|
|
|
3
3
|
import { $provideExecutionToolsForNode } from '../execution/utils/$provideExecutionToolsForNode';
|
|
4
4
|
import { $provideLlmToolsConfigurationFromEnv } from '../llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv';
|
|
5
5
|
import { $provideLlmToolsFromEnv } from '../llm-providers/_common/register/$provideLlmToolsFromEnv';
|
|
6
|
+
import { $provideFilesystemForNode } from '../scrapers/_common/register/$provideFilesystemForNode';
|
|
6
7
|
import { $provideScrapersForNode } from '../scrapers/_common/register/$provideScrapersForNode';
|
|
7
8
|
import { FileCacheStorage } from '../storage/file-cache-storage/FileCacheStorage';
|
|
8
9
|
import { $execCommand } from '../utils/execCommand/$execCommand';
|
|
@@ -12,6 +13,7 @@ export { createCollectionFromDirectory };
|
|
|
12
13
|
export { $provideExecutionToolsForNode };
|
|
13
14
|
export { $provideLlmToolsConfigurationFromEnv };
|
|
14
15
|
export { $provideLlmToolsFromEnv };
|
|
16
|
+
export { $provideFilesystemForNode };
|
|
15
17
|
export { $provideScrapersForNode };
|
|
16
18
|
export { FileCacheStorage };
|
|
17
19
|
export { $execCommand };
|
|
@@ -20,6 +20,7 @@ import type { CreatePipelineExecutorOptions } from '../execution/createPipelineE
|
|
|
20
20
|
import type { CreatePipelineExecutorSettings } from '../execution/createPipelineExecutor/00-CreatePipelineExecutorSettings';
|
|
21
21
|
import type { EmbeddingVector } from '../execution/EmbeddingVector';
|
|
22
22
|
import type { ExecutionTools } from '../execution/ExecutionTools';
|
|
23
|
+
import type { FilesystemTools } from '../execution/FilesystemTools';
|
|
23
24
|
import type { LlmExecutionTools } from '../execution/LlmExecutionTools';
|
|
24
25
|
import type { LlmExecutionToolsConstructor } from '../execution/LlmExecutionToolsConstructor';
|
|
25
26
|
import type { PipelineExecutor } from '../execution/PipelineExecutor';
|
|
@@ -259,6 +260,7 @@ export type { CreatePipelineExecutorOptions };
|
|
|
259
260
|
export type { CreatePipelineExecutorSettings };
|
|
260
261
|
export type { EmbeddingVector };
|
|
261
262
|
export type { ExecutionTools };
|
|
263
|
+
export type { FilesystemTools };
|
|
262
264
|
export type { LlmExecutionTools };
|
|
263
265
|
export type { LlmExecutionToolsConstructor };
|
|
264
266
|
export type { PipelineExecutor };
|
|
@@ -46,9 +46,9 @@ type CreatePipelineCollectionFromDirectoryOptions = Omit<PrepareAndScrapeOptions
|
|
|
46
46
|
* @returns PipelineCollection
|
|
47
47
|
* @public exported from `@promptbook/node`
|
|
48
48
|
*/
|
|
49
|
-
export declare function createCollectionFromDirectory(path: string_dirname, tools?: Pick<ExecutionTools, 'llm' | 'scrapers'>, options?: CreatePipelineCollectionFromDirectoryOptions): Promise<PipelineCollection>;
|
|
49
|
+
export declare function createCollectionFromDirectory(path: string_dirname, tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options?: CreatePipelineCollectionFromDirectoryOptions): Promise<PipelineCollection>;
|
|
50
50
|
export {};
|
|
51
51
|
/**
|
|
52
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
53
52
|
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
53
|
+
* TODO: Maybe move from `@promptbook/node` to `@promptbook/core` as we removes direct dependency on `fs`
|
|
54
54
|
*/
|
|
@@ -20,7 +20,7 @@ import type { PipelineString } from '../types/PipelineString';
|
|
|
20
20
|
* @throws {ParseError} if the promptbook string is not valid
|
|
21
21
|
* @public exported from `@promptbook/core`
|
|
22
22
|
*/
|
|
23
|
-
export declare function pipelineStringToJson(pipelineString: PipelineString, tools?: Pick<ExecutionTools, 'llm' | 'scrapers'>, options?: PrepareAndScrapeOptions): Promise<PipelineJson>;
|
|
23
|
+
export declare function pipelineStringToJson(pipelineString: PipelineString, tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options?: PrepareAndScrapeOptions): Promise<PipelineJson>;
|
|
24
24
|
/**
|
|
25
25
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
26
26
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Scraper } from '../scrapers/_common/Scraper';
|
|
2
2
|
import type { Arrayable } from '../types/Arrayable';
|
|
3
|
+
import type { FilesystemTools } from './FilesystemTools';
|
|
3
4
|
import type { LlmExecutionTools } from './LlmExecutionTools';
|
|
4
5
|
import type { ScriptExecutionTools } from './ScriptExecutionTools';
|
|
5
6
|
import type { UserInterfaceTools } from './UserInterfaceTools';
|
|
@@ -12,11 +13,19 @@ export type ExecutionTools = {
|
|
|
12
13
|
/**
|
|
13
14
|
* Tools for executing prompts in large language models
|
|
14
15
|
*
|
|
15
|
-
* Tip: Use `$provideLlmToolsFromEnv
|
|
16
|
+
* Tip: Use `$provideLlmToolsFromEnv` to use all available LLM providers you configured
|
|
16
17
|
*
|
|
17
18
|
* @default [] - If not provided, no LLM execution will be possible - it does not make sense in most cases
|
|
18
19
|
*/
|
|
19
20
|
readonly llm?: Arrayable<LlmExecutionTools>;
|
|
21
|
+
/**
|
|
22
|
+
* Tools for filesystem operations
|
|
23
|
+
*
|
|
24
|
+
* Tip: Use `$provideFilesystemForNode` to use filesystem in Node.js
|
|
25
|
+
*
|
|
26
|
+
* @default undefined - If not provided, no filesystem operations will be possible
|
|
27
|
+
*/
|
|
28
|
+
readonly fs?: FilesystemTools;
|
|
20
29
|
/**
|
|
21
30
|
* Scrapers for extracting knowledge from external sources
|
|
22
31
|
*
|
|
@@ -30,7 +39,7 @@ export type ExecutionTools = {
|
|
|
30
39
|
*
|
|
31
40
|
* Note: You can pass multiple ScriptExecutionTools, they will be tried one by one until one of them supports the script
|
|
32
41
|
* If none of them supports the script, an error is thrown
|
|
33
|
-
* Tip: Use here `new JavascriptExecutionTools
|
|
42
|
+
* Tip: Use here `new JavascriptExecutionTools`
|
|
34
43
|
*
|
|
35
44
|
* @default [] - If not provided, no script execution will be possible
|
|
36
45
|
*/
|
|
@@ -43,6 +52,7 @@ export type ExecutionTools = {
|
|
|
43
52
|
readonly userInterface?: UserInterfaceTools;
|
|
44
53
|
};
|
|
45
54
|
/**
|
|
55
|
+
* TODO: !!!!!! Move here also the executables and make $provideXxxxForNode
|
|
46
56
|
* TODO: [🍂] Maybe make llm = $provideLlmToolsFromEnv() without problem with bundle contaminated by only `@promptbook/node` and `@promptbook/cli` stuff
|
|
47
57
|
* TODO: [🍂] Same with scrapers
|
|
48
58
|
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fs from 'fs/promises';
|
|
3
|
+
/**
|
|
4
|
+
* Container for all the tools needed to manipulate with filesystem
|
|
5
|
+
*/
|
|
6
|
+
export type FilesystemTools = Pick<typeof fs, 'access' | 'constants' | 'readFile' | 'stat' | 'readdir'>;
|
|
7
|
+
/**
|
|
8
|
+
* TODO: Implement destroyable pattern to free resources
|
|
9
|
+
*/
|
|
@@ -8,4 +8,5 @@ export declare function translateMessages({ automaticTranslator, from, to, }: {
|
|
|
8
8
|
} & TranslatorOptions): Promise<void>;
|
|
9
9
|
/**
|
|
10
10
|
* TODO: [😶] Unite floder listing
|
|
11
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
11
12
|
*/
|
|
@@ -9,7 +9,7 @@ import type { PrepareAndScrapeOptions } from './PrepareAndScrapeOptions';
|
|
|
9
9
|
* Note: When the pipeline is already prepared, it returns the same pipeline
|
|
10
10
|
* @public exported from `@promptbook/core`
|
|
11
11
|
*/
|
|
12
|
-
export declare function preparePipeline(pipeline: PipelineJson, tools: Pick<ExecutionTools, 'llm' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<PipelineJson>;
|
|
12
|
+
export declare function preparePipeline(pipeline: PipelineJson, tools: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<PipelineJson>;
|
|
13
13
|
/**
|
|
14
14
|
* TODO: Write tests for `preparePipeline`
|
|
15
15
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
@@ -19,7 +19,7 @@ type PreparedTemplates = {
|
|
|
19
19
|
*
|
|
20
20
|
* @public exported from `@promptbook/core`
|
|
21
21
|
*/
|
|
22
|
-
export declare function prepareTemplates(pipeline: PrepareTemplateInput, tools: Pick<ExecutionTools, 'llm' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<PreparedTemplates>;
|
|
22
|
+
export declare function prepareTemplates(pipeline: PrepareTemplateInput, tools: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<PreparedTemplates>;
|
|
23
23
|
export {};
|
|
24
24
|
/**
|
|
25
25
|
* TODO: [🧠] Add context to each template (if missing)
|
|
@@ -8,7 +8,7 @@ import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
|
8
8
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
9
9
|
* @public exported from `@promptbook/core`
|
|
10
10
|
*/
|
|
11
|
-
export declare function prepareKnowledgePieces(knowledgeSources: Array<KnowledgeSourceJson>, tools: Pick<ExecutionTools, 'llm' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<Array<Omit<KnowledgePiecePreparedJson, 'preparationIds'>>>;
|
|
11
|
+
export declare function prepareKnowledgePieces(knowledgeSources: Array<KnowledgeSourceJson>, tools: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<Array<Omit<KnowledgePiecePreparedJson, 'preparationIds'>>>;
|
|
12
12
|
/**
|
|
13
13
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
14
14
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FilesystemTools } from '../../../execution/FilesystemTools';
|
|
2
|
+
import type { PrepareAndScrapeOptions } from '../../../prepare/PrepareAndScrapeOptions';
|
|
3
|
+
/**
|
|
4
|
+
* @@@
|
|
5
|
+
*
|
|
6
|
+
* @public exported from `@promptbook/node`
|
|
7
|
+
*/
|
|
8
|
+
export declare function $provideFilesystemForNode(options?: Pick<PrepareAndScrapeOptions, 'isVerbose'>): FilesystemTools;
|
|
9
|
+
/**
|
|
10
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
11
|
+
*/
|
|
@@ -30,4 +30,5 @@ export {};
|
|
|
30
30
|
* 1) Need to store more than serialized JSONs
|
|
31
31
|
* 2) Need to switch between a `rootDirname` and `cacheDirname` <- TODO: !!!!
|
|
32
32
|
* TODO: [🐱🐉][🧠] Make some smart crop
|
|
33
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
33
34
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SetOptional } from 'type-fest';
|
|
2
|
+
import type { ExecutionTools } from '../../../execution/ExecutionTools';
|
|
2
3
|
import type { PrepareAndScrapeOptions } from '../../../prepare/PrepareAndScrapeOptions';
|
|
3
4
|
import type { KnowledgeSourceJson } from '../../../types/PipelineJson/KnowledgeSourceJson';
|
|
4
5
|
import type { ScraperSourceHandler } from '../Scraper';
|
|
@@ -7,7 +8,4 @@ import type { ScraperSourceHandler } from '../Scraper';
|
|
|
7
8
|
*
|
|
8
9
|
* @private for scraper utilities
|
|
9
10
|
*/
|
|
10
|
-
export declare function makeKnowledgeSourceHandler(knowledgeSource: SetOptional<KnowledgeSourceJson, 'name'>, options?: Pick<PrepareAndScrapeOptions, 'rootDirname' | 'isVerbose'>): Promise<ScraperSourceHandler>;
|
|
11
|
-
/**
|
|
12
|
-
* TODO: !!!!!!! Maybe constrain to @promptbook/node bundle
|
|
13
|
-
*/
|
|
11
|
+
export declare function makeKnowledgeSourceHandler(knowledgeSource: SetOptional<KnowledgeSourceJson, 'name'>, tools: Pick<ExecutionTools, 'fs'>, options?: Pick<PrepareAndScrapeOptions, 'rootDirname' | 'isVerbose'>): Promise<ScraperSourceHandler>;
|
|
@@ -23,7 +23,7 @@ export declare class DocumentScraper implements Converter, Scraper {
|
|
|
23
23
|
* Markdown scraper is used internally
|
|
24
24
|
*/
|
|
25
25
|
private readonly markdownScraper;
|
|
26
|
-
constructor(tools: Pick<ExecutionTools, 'llm'>, options: PrepareAndScrapeOptions);
|
|
26
|
+
constructor(tools: Pick<ExecutionTools, 'fs' | 'llm'>, options: PrepareAndScrapeOptions);
|
|
27
27
|
/**
|
|
28
28
|
* Convert the `.docx` or `.odt` to `.md` file and returns intermediate source
|
|
29
29
|
*
|
|
@@ -23,7 +23,7 @@ export declare class LegacyDocumentScraper implements Converter, Scraper {
|
|
|
23
23
|
* Document scraper is used internally
|
|
24
24
|
*/
|
|
25
25
|
private readonly documentScraper;
|
|
26
|
-
constructor(tools: Pick<ExecutionTools, 'llm'>, options: PrepareAndScrapeOptions);
|
|
26
|
+
constructor(tools: Pick<ExecutionTools, 'fs' | 'llm'>, options: PrepareAndScrapeOptions);
|
|
27
27
|
/**
|
|
28
28
|
* Convert the `.doc` or `.rtf` to `.doc` file and returns intermediate source
|
|
29
29
|
*
|
|
@@ -24,7 +24,7 @@ export declare class WebsiteScraper implements Converter, Scraper {
|
|
|
24
24
|
* Markdown scraper is used internally
|
|
25
25
|
*/
|
|
26
26
|
private readonly markdownScraper;
|
|
27
|
-
constructor(tools: Pick<ExecutionTools, 'llm'>, options: PrepareAndScrapeOptions);
|
|
27
|
+
constructor(tools: Pick<ExecutionTools, 'fs' | 'llm'>, options: PrepareAndScrapeOptions);
|
|
28
28
|
/**
|
|
29
29
|
* Convert the website to `.md` file and returns intermediate source
|
|
30
30
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
1
2
|
import type { PromptbookStorage } from '../_common/PromptbookStorage';
|
|
2
3
|
import type { FileCacheStorageOptions } from './FileCacheStorageOptions';
|
|
3
4
|
/**
|
|
@@ -6,8 +7,9 @@ import type { FileCacheStorageOptions } from './FileCacheStorageOptions';
|
|
|
6
7
|
* @public exported from `@promptbook/node`
|
|
7
8
|
*/
|
|
8
9
|
export declare class FileCacheStorage<TItem> implements PromptbookStorage<TItem> {
|
|
10
|
+
private readonly tools;
|
|
9
11
|
private readonly options;
|
|
10
|
-
constructor(options: FileCacheStorageOptions);
|
|
12
|
+
constructor(tools: Required<Pick<ExecutionTools, 'fs'>>, options: FileCacheStorageOptions);
|
|
11
13
|
/**
|
|
12
14
|
* @@@
|
|
13
15
|
*/
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import type { FilesystemTools } from '../../execution/FilesystemTools';
|
|
1
2
|
import type { string_dirname } from '../../types/typeAliases';
|
|
2
3
|
/**
|
|
3
4
|
* Checks if the directory exists
|
|
4
5
|
*
|
|
5
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
6
|
-
*
|
|
7
6
|
* @private within the repository
|
|
8
7
|
*/
|
|
9
|
-
export declare function
|
|
8
|
+
export declare function isDirectoryExisting(directoryPath: string_dirname, fs: FilesystemTools): Promise<boolean>;
|
|
10
9
|
/**
|
|
11
|
-
* Note: [
|
|
10
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
12
11
|
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
13
12
|
* TODO: [🧠][📂] "directory" vs "folder"
|
|
14
13
|
* TODO: [🖇] What about symlinks?
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FilesystemTools } from '../../execution/FilesystemTools';
|
|
2
|
+
import type { string_filename } from '../../types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the file exists
|
|
5
|
+
*
|
|
6
|
+
* @private within the repository
|
|
7
|
+
*/
|
|
8
|
+
export declare function isFileExisting(filename: string_filename, fs: FilesystemTools): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
11
|
+
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
12
|
+
* TODO: [🖇] What about symlinks?
|
|
13
|
+
*/
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import type { FilesystemTools } from '../../execution/FilesystemTools';
|
|
1
2
|
import type { string_dirname } from '../../types/typeAliases';
|
|
2
3
|
import type { string_filename } from '../../types/typeAliases';
|
|
3
4
|
/**
|
|
4
5
|
* Reads all files in the directory
|
|
5
6
|
*
|
|
6
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
7
|
-
*
|
|
8
7
|
* @param path
|
|
9
8
|
* @param isRecursive
|
|
10
9
|
* @returns List of all files in the directory
|
|
11
10
|
* @private internal function of `createCollectionFromDirectory`
|
|
12
11
|
*/
|
|
13
|
-
export declare function
|
|
12
|
+
export declare function listAllFiles(path: string_dirname, isRecursive: boolean, fs: FilesystemTools): Promise<Array<string_filename>>;
|
|
14
13
|
/**
|
|
15
14
|
* TODO: [😶] Unite floder listing
|
|
16
|
-
* Note: [
|
|
15
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
17
16
|
* TODO: [🖇] What about symlinks?
|
|
18
17
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.71.0-
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.71.0-13';
|
|
20
20
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
@@ -5263,39 +5263,45 @@
|
|
|
5263
5263
|
*/
|
|
5264
5264
|
|
|
5265
5265
|
/**
|
|
5266
|
-
*
|
|
5266
|
+
* Convert file extension to mime type
|
|
5267
5267
|
*
|
|
5268
|
-
*
|
|
5268
|
+
* @private within the repository
|
|
5269
|
+
*/
|
|
5270
|
+
function extensionToMimeType(value) {
|
|
5271
|
+
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
5272
|
+
}
|
|
5273
|
+
|
|
5274
|
+
/**
|
|
5275
|
+
* Get the file extension from a file name
|
|
5269
5276
|
*
|
|
5270
|
-
* @
|
|
5277
|
+
* @private within the repository
|
|
5271
5278
|
*/
|
|
5272
|
-
|
|
5279
|
+
function getFileExtension(value) {
|
|
5280
|
+
var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
|
|
5281
|
+
return match ? match[1].toLowerCase() : null;
|
|
5282
|
+
}
|
|
5273
5283
|
|
|
5274
5284
|
/**
|
|
5275
5285
|
* Checks if the file exists
|
|
5276
5286
|
*
|
|
5277
|
-
* Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
|
|
5278
|
-
*
|
|
5279
5287
|
* @private within the repository
|
|
5280
5288
|
*/
|
|
5281
|
-
function
|
|
5289
|
+
function isFileExisting(filename, fs) {
|
|
5282
5290
|
return __awaiter(this, void 0, void 0, function () {
|
|
5283
5291
|
var isReadAccessAllowed, isFile;
|
|
5284
5292
|
return __generator(this, function (_a) {
|
|
5285
5293
|
switch (_a.label) {
|
|
5286
|
-
case 0:
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
return [4 /*yield*/, promises.access(filename, promises.constants.R_OK)
|
|
5291
|
-
.then(function () { return true; })
|
|
5292
|
-
.catch(function () { return false; })];
|
|
5294
|
+
case 0: return [4 /*yield*/, fs
|
|
5295
|
+
.access(filename, fs.constants.R_OK)
|
|
5296
|
+
.then(function () { return true; })
|
|
5297
|
+
.catch(function () { return false; })];
|
|
5293
5298
|
case 1:
|
|
5294
5299
|
isReadAccessAllowed = _a.sent();
|
|
5295
5300
|
if (!isReadAccessAllowed) {
|
|
5296
5301
|
return [2 /*return*/, false];
|
|
5297
5302
|
}
|
|
5298
|
-
return [4 /*yield*/,
|
|
5303
|
+
return [4 /*yield*/, fs
|
|
5304
|
+
.stat(filename)
|
|
5299
5305
|
.then(function (fileStat) { return fileStat.isFile(); })
|
|
5300
5306
|
.catch(function () { return false; })];
|
|
5301
5307
|
case 2:
|
|
@@ -5306,30 +5312,11 @@
|
|
|
5306
5312
|
});
|
|
5307
5313
|
}
|
|
5308
5314
|
/**
|
|
5309
|
-
* Note: [
|
|
5315
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
5310
5316
|
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
5311
5317
|
* TODO: [🖇] What about symlinks?
|
|
5312
5318
|
*/
|
|
5313
5319
|
|
|
5314
|
-
/**
|
|
5315
|
-
* Convert file extension to mime type
|
|
5316
|
-
*
|
|
5317
|
-
* @private within the repository
|
|
5318
|
-
*/
|
|
5319
|
-
function extensionToMimeType(value) {
|
|
5320
|
-
return mimeTypes.lookup(value) || 'application/octet-stream';
|
|
5321
|
-
}
|
|
5322
|
-
|
|
5323
|
-
/**
|
|
5324
|
-
* Get the file extension from a file name
|
|
5325
|
-
*
|
|
5326
|
-
* @private within the repository
|
|
5327
|
-
*/
|
|
5328
|
-
function getFileExtension(value) {
|
|
5329
|
-
var match = value.match(/\.([0-9a-z]+)(?:[?#]|$)/i);
|
|
5330
|
-
return match ? match[1].toLowerCase() : null;
|
|
5331
|
-
}
|
|
5332
|
-
|
|
5333
5320
|
/**
|
|
5334
5321
|
* Tests if given string is valid URL.
|
|
5335
5322
|
*
|
|
@@ -5361,7 +5348,7 @@
|
|
|
5361
5348
|
*
|
|
5362
5349
|
* @private for scraper utilities
|
|
5363
5350
|
*/
|
|
5364
|
-
function makeKnowledgeSourceHandler(knowledgeSource, options) {
|
|
5351
|
+
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5365
5352
|
var _a;
|
|
5366
5353
|
return __awaiter(this, void 0, void 0, function () {
|
|
5367
5354
|
var sourceContent, name, _b, _c, rootDirname, _d,
|
|
@@ -5430,8 +5417,9 @@
|
|
|
5430
5417
|
}];
|
|
5431
5418
|
case 2:
|
|
5432
5419
|
if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
|
|
5433
|
-
if (
|
|
5434
|
-
throw new EnvironmentMismatchError('
|
|
5420
|
+
if (tools.fs === undefined) {
|
|
5421
|
+
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
5422
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
5435
5423
|
}
|
|
5436
5424
|
if (rootDirname === null) {
|
|
5437
5425
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
@@ -5440,7 +5428,7 @@
|
|
|
5440
5428
|
filename_1 = path.join(rootDirname, sourceContent).split('\\').join('/');
|
|
5441
5429
|
fileExtension = getFileExtension(filename_1);
|
|
5442
5430
|
mimeType_1 = extensionToMimeType(fileExtension || '');
|
|
5443
|
-
return [4 /*yield*/,
|
|
5431
|
+
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5444
5432
|
case 3:
|
|
5445
5433
|
if (!(_e.sent())) {
|
|
5446
5434
|
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 "); }));
|
|
@@ -5456,7 +5444,7 @@
|
|
|
5456
5444
|
var content;
|
|
5457
5445
|
return __generator(this, function (_a) {
|
|
5458
5446
|
switch (_a.label) {
|
|
5459
|
-
case 0: return [4 /*yield*/,
|
|
5447
|
+
case 0: return [4 /*yield*/, tools.fs.readFile(filename_1)];
|
|
5460
5448
|
case 1:
|
|
5461
5449
|
content = _a.sent();
|
|
5462
5450
|
return [2 /*return*/, new Blob([
|
|
@@ -5510,9 +5498,6 @@
|
|
|
5510
5498
|
});
|
|
5511
5499
|
});
|
|
5512
5500
|
}
|
|
5513
|
-
/**
|
|
5514
|
-
* TODO: !!!!!!! Maybe constrain to @promptbook/node bundle
|
|
5515
|
-
*/
|
|
5516
5501
|
|
|
5517
5502
|
/**
|
|
5518
5503
|
* Prepares the knowle
|
|
@@ -5536,7 +5521,7 @@
|
|
|
5536
5521
|
switch (_d.label) {
|
|
5537
5522
|
case 0:
|
|
5538
5523
|
partialPieces = null;
|
|
5539
|
-
return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, { rootDirname: rootDirname, isVerbose: isVerbose })];
|
|
5524
|
+
return [4 /*yield*/, makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname: rootDirname, isVerbose: isVerbose })];
|
|
5540
5525
|
case 1:
|
|
5541
5526
|
sourceHandler = _d.sent();
|
|
5542
5527
|
_d.label = 2;
|