@promptbook/website-crawler 0.84.0-10 โ†’ 0.84.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/esm/index.es.js CHANGED
@@ -8,6 +8,7 @@ import { basename, join, dirname } from 'path';
8
8
  import { format } from 'prettier';
9
9
  import parserHtml from 'prettier/parser-html';
10
10
  import { forTime } from 'waitasecond';
11
+ import sha256 from 'crypto-js/sha256';
11
12
  import { lookup } from 'mime-types';
12
13
  import { unparse, parse } from 'papaparse';
13
14
  import { Converter } from 'showdown';
@@ -26,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
26
27
  * @generated
27
28
  * @see https://github.com/webgptorg/promptbook
28
29
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-9';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
30
31
  /**
31
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
33
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -268,6 +269,12 @@ var SMALL_NUMBER = 0.001;
268
269
  * @private within the repository - too low-level in comparison with other `MAX_...`
269
270
  */
270
271
  var IMMEDIATE_TIME = 10;
272
+ /**
273
+ * The maximum length of the (generated) filename
274
+ *
275
+ * @public exported from `@promptbook/core`
276
+ */
277
+ var MAX_FILENAME_LENGTH = 30;
271
278
  /**
272
279
  * Strategy for caching the intermediate results for knowledge sources
273
280
  *
@@ -287,6 +294,15 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
287
294
  * @public exported from `@promptbook/core`
288
295
  */
289
296
  var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
297
+ // <- TODO: [๐Ÿ•] Make also `BOOKS_DIRNAME_ALTERNATIVES`
298
+ /**
299
+ * Where to store the temporary downloads
300
+ *
301
+ * Note: When the folder does not exist, it is created recursively
302
+ *
303
+ * @public exported from `@promptbook/core`
304
+ */
305
+ var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
290
306
  /**
291
307
  * Where to store the scrape cache
292
308
  *
@@ -1119,24 +1135,18 @@ function getScraperIntermediateSource(source, options) {
1119
1135
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [๐Ÿ†] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [๐Ÿ†] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โœ Convert Knowledge-piece to title\" but \"โœ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โœ Convert Knowledge-piece to title\" but \"โœ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
1120
1136
 
1121
1137
  /**
1122
- * Function isValidJsonString will tell you if the string is valid JSON or not
1138
+ * Checks if value is valid email
1123
1139
  *
1124
1140
  * @public exported from `@promptbook/utils`
1125
1141
  */
1126
- function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
1127
- try {
1128
- JSON.parse(value);
1129
- return true;
1142
+ function isValidEmail(email) {
1143
+ if (typeof email !== 'string') {
1144
+ return false;
1130
1145
  }
1131
- catch (error) {
1132
- if (!(error instanceof Error)) {
1133
- throw error;
1134
- }
1135
- if (error.message.includes('Unexpected token')) {
1136
- return false;
1137
- }
1146
+ if (email.split('\n').length > 1) {
1138
1147
  return false;
1139
1148
  }
1149
+ return /^.+@.+\..+$/.test(email);
1140
1150
  }
1141
1151
 
1142
1152
  /**
@@ -1158,6 +1168,27 @@ var ParseError = /** @class */ (function (_super) {
1158
1168
  * TODO: Maybe split `ParseError` and `ApplyError`
1159
1169
  */
1160
1170
 
1171
+ /**
1172
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1173
+ *
1174
+ * @public exported from `@promptbook/utils`
1175
+ */
1176
+ function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
1177
+ try {
1178
+ JSON.parse(value);
1179
+ return true;
1180
+ }
1181
+ catch (error) {
1182
+ if (!(error instanceof Error)) {
1183
+ throw error;
1184
+ }
1185
+ if (error.message.includes('Unexpected token')) {
1186
+ return false;
1187
+ }
1188
+ return false;
1189
+ }
1190
+ }
1191
+
1161
1192
  /**
1162
1193
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1163
1194
  * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
@@ -1171,6 +1202,15 @@ function validatePipelineString(pipelineString) {
1171
1202
  if (isValidJsonString(pipelineString)) {
1172
1203
  throw new ParseError('Expected a book, but got a JSON string');
1173
1204
  }
1205
+ else if (isValidUrl(pipelineString)) {
1206
+ throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
1207
+ }
1208
+ else if (isValidFilePath(pipelineString)) {
1209
+ throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
1210
+ }
1211
+ else if (isValidEmail(pipelineString)) {
1212
+ throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
1213
+ }
1174
1214
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1175
1215
  return pipelineString;
1176
1216
  }
@@ -2498,12 +2538,28 @@ function deserializeError(error) {
2498
2538
  /**
2499
2539
  * Asserts that the execution of a Promptbook is successful
2500
2540
  *
2541
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
2542
+ *
2501
2543
  * @param executionResult - The partial result of the Promptbook execution
2502
2544
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2503
2545
  * @public exported from `@promptbook/core`
2504
2546
  */
2505
2547
  function assertsExecutionSuccessful(executionResult) {
2506
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2548
+ var e_1, _a;
2549
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2550
+ try {
2551
+ for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
2552
+ var warning = warnings_1_1.value;
2553
+ console.warn(warning.message);
2554
+ }
2555
+ }
2556
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2557
+ finally {
2558
+ try {
2559
+ if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
2560
+ }
2561
+ finally { if (e_1) throw e_1.error; }
2562
+ }
2507
2563
  if (isSuccessful === true) {
2508
2564
  return;
2509
2565
  }
@@ -3569,10 +3625,11 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
3569
3625
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3570
3626
  var _a;
3571
3627
  return __awaiter(this, void 0, void 0, function () {
3572
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3573
- return __generator(this, function (_f) {
3574
- switch (_f.label) {
3628
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response, mimeType, filename, hash, rootDirname_1, filepath, _f, _g, _h, _j, _k, filename_1, fileExtension, mimeType;
3629
+ return __generator(this, function (_l) {
3630
+ switch (_l.label) {
3575
3631
  case 0:
3632
+ console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
3576
3633
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
3577
3634
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
3578
3635
  name = knowledgeSource.name;
@@ -3580,54 +3637,32 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3580
3637
  if (!name) {
3581
3638
  name = knowledgeSourceContentToName(knowledgeSourceContent);
3582
3639
  }
3583
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
3640
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
3584
3641
  url = knowledgeSourceContent;
3585
3642
  return [4 /*yield*/, fetch(url)];
3586
3643
  case 1:
3587
- response_1 = _f.sent();
3588
- mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3589
- return [2 /*return*/, {
3590
- source: name,
3591
- filename: null,
3592
- url: url,
3593
- mimeType: mimeType,
3594
- /*
3595
- TODO: [๐Ÿฅฝ]
3596
- > async asBlob() {
3597
- > // TODO: [๐Ÿ‘จ๐Ÿปโ€๐Ÿคโ€๐Ÿ‘จ๐Ÿป] This can be called multiple times BUT when called second time, response in already consumed
3598
- > const content = await response.blob();
3599
- > return content;
3600
- > },
3601
- */
3602
- asJson: function () {
3603
- return __awaiter(this, void 0, void 0, function () {
3604
- var content;
3605
- return __generator(this, function (_a) {
3606
- switch (_a.label) {
3607
- case 0: return [4 /*yield*/, response_1.json()];
3608
- case 1:
3609
- content = _a.sent();
3610
- return [2 /*return*/, content];
3611
- }
3612
- });
3613
- });
3614
- },
3615
- asText: function () {
3616
- return __awaiter(this, void 0, void 0, function () {
3617
- var content;
3618
- return __generator(this, function (_a) {
3619
- switch (_a.label) {
3620
- case 0: return [4 /*yield*/, response_1.text()];
3621
- case 1:
3622
- content = _a.sent();
3623
- return [2 /*return*/, content];
3624
- }
3625
- });
3626
- });
3627
- },
3628
- }];
3644
+ response = _l.sent();
3645
+ mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3646
+ filename = url.split('/').pop() || titleToName(url);
3647
+ hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
3648
+ rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3649
+ filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [๐ŸŽŽ] Maybe add some SHA256 prefix */)), false), ["".concat(filename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
3650
+ return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
3629
3651
  case 2:
3630
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
3652
+ _l.sent();
3653
+ _g = (_f = tools.fs).writeFile;
3654
+ _h = [join(rootDirname_1, filepath)];
3655
+ _k = (_j = Buffer).from;
3656
+ return [4 /*yield*/, response.arrayBuffer()];
3657
+ case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
3658
+ case 4:
3659
+ _l.sent();
3660
+ // TODO: !!!!!!!! Check the file security
3661
+ // TODO: !!!!!!!! Check the file size (if it is not too big)
3662
+ // TODO: !!!!!!!! Delete the file
3663
+ return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
3664
+ case 5:
3665
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
3631
3666
  if (tools.fs === undefined) {
3632
3667
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3633
3668
  // <- TODO: [๐Ÿง ] What is the best error type here`
@@ -3640,8 +3675,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3640
3675
  fileExtension = getFileExtension(filename_1);
3641
3676
  mimeType = extensionToMimeType(fileExtension || '');
3642
3677
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3643
- case 3:
3644
- if (!(_f.sent())) {
3678
+ case 6:
3679
+ if (!(_l.sent())) {
3645
3680
  throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
3646
3681
  }
3647
3682
  // TODO: [๐Ÿง ][๐Ÿ˜ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -3687,7 +3722,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3687
3722
  });
3688
3723
  },
3689
3724
  }];
3690
- case 4: return [2 /*return*/, {
3725
+ case 7: return [2 /*return*/, {
3691
3726
  source: name,
3692
3727
  filename: null,
3693
3728
  url: null,