@promptbook/remote-server 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.
Files changed (27) hide show
  1. package/esm/index.es.js +1 -1
  2. package/esm/typings/src/_packages/node.index.d.ts +2 -0
  3. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  4. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -2
  5. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -1
  6. package/esm/typings/src/execution/ExecutionTools.d.ts +12 -2
  7. package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
  8. package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -0
  9. package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
  10. package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
  11. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +1 -1
  12. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
  13. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +1 -0
  14. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +2 -4
  15. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
  16. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
  17. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
  18. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +3 -1
  19. package/esm/typings/src/utils/files/{$isDirectoryExisting.d.ts → isDirectoryExisting.d.ts} +3 -4
  20. package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
  21. package/esm/typings/src/utils/files/{$listAllFiles.d.ts → listAllFiles.d.ts} +3 -4
  22. package/package.json +2 -2
  23. package/umd/index.umd.js +1 -1
  24. package/esm/typings/src/utils/files/$isFileExisting.d.ts +0 -14
  25. /package/esm/typings/src/utils/files/{$isDirectoryExisting.test.d.ts → isDirectoryExisting.test.d.ts} +0 -0
  26. /package/esm/typings/src/utils/files/{$isFileExisting.test.d.ts → isFileExisting.test.d.ts} +0 -0
  27. /package/esm/typings/src/utils/files/{$listAllFiles.test.d.ts → listAllFiles.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -7,7 +7,7 @@ import spaceTrim$1, { spaceTrim } from 'spacetrim';
7
7
  /**
8
8
  * The version of the Promptbook library
9
9
  */
10
- var PROMPTBOOK_VERSION = '0.71.0-12';
10
+ var PROMPTBOOK_VERSION = '0.71.0-13';
11
11
  // TODO: [main] !!!! List here all the versions and annotate + put into script
12
12
 
13
13
  /*! *****************************************************************************
@@ -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()` to use all available LLM providers you configured
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 $isDirectoryExisting(directoryPath: string_dirname): Promise<boolean>;
8
+ export declare function isDirectoryExisting(directoryPath: string_dirname, fs: FilesystemTools): Promise<boolean>;
10
9
  /**
11
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
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 $listAllFiles(path: string_dirname, isRecursive: boolean): Promise<Array<string_filename>>;
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: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
15
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
17
16
  * TODO: [🖇] What about symlinks?
18
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.71.0-13",
3
+ "version": "0.71.0-14",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -51,7 +51,7 @@
51
51
  "module": "./esm/index.es.js",
52
52
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
53
53
  "peerDependencies": {
54
- "@promptbook/core": "0.71.0-13"
54
+ "@promptbook/core": "0.71.0-14"
55
55
  },
56
56
  "dependencies": {
57
57
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -14,7 +14,7 @@
14
14
  /**
15
15
  * The version of the Promptbook library
16
16
  */
17
- var PROMPTBOOK_VERSION = '0.71.0-12';
17
+ var PROMPTBOOK_VERSION = '0.71.0-13';
18
18
  // TODO: [main] !!!! List here all the versions and annotate + put into script
19
19
 
20
20
  /*! *****************************************************************************
@@ -1,14 +0,0 @@
1
- import type { string_filename } from '../../types/typeAliases';
2
- /**
3
- * Checks if the file exists
4
- *
5
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
6
- *
7
- * @private within the repository
8
- */
9
- export declare function $isFileExisting(filename: string_filename): Promise<boolean>;
10
- /**
11
- * Note: [🟢 !!!!!! After fix makeKnowledgeSourceHandler] Code in this file should never be published outside of `@promptbook/node` and `@promptbook/cli`
12
- * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
13
- * TODO: [🖇] What about symlinks?
14
- */