@promptbook/pdf 0.84.0-20 → 0.84.0-9
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 +5 -11
- package/esm/index.es.js +69 -165
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +0 -4
- package/esm/typings/src/_packages/core.index.d.ts +2 -12
- package/esm/typings/src/_packages/types.index.d.ts +0 -2
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/esm/typings/src/_packages/wizzard.index.d.ts +0 -4
- package/esm/typings/src/config.d.ts +1 -27
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -3
- package/esm/typings/src/pipeline/book-notation.d.ts +2 -3
- package/esm/typings/src/pipeline/prompt-notation.d.ts +5 -18
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -5
- package/esm/typings/src/wizzard/wizzard.d.ts +1 -7
- package/package.json +16 -9
- package/umd/index.umd.js +72 -168
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +0 -9
- package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +0 -14
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +0 -14
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +0 -15
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +0 -1
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +0 -1
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +0 -10
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +0 -1
package/umd/index.umd.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'waitasecond', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.waitasecond, global.
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, waitasecond,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'waitasecond', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.waitasecond, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, waitasecond, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
10
10
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
11
11
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
12
|
-
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
13
12
|
|
|
14
13
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
15
14
|
/**
|
|
@@ -25,7 +24,7 @@
|
|
|
25
24
|
* @generated
|
|
26
25
|
* @see https://github.com/webgptorg/promptbook
|
|
27
26
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
27
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
|
|
29
28
|
/**
|
|
30
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -196,12 +195,6 @@
|
|
|
196
195
|
* @public exported from `@promptbook/core`
|
|
197
196
|
*/
|
|
198
197
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
199
|
-
/**
|
|
200
|
-
* Maximum file size limit
|
|
201
|
-
*
|
|
202
|
-
* @public exported from `@promptbook/core`
|
|
203
|
-
*/
|
|
204
|
-
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
205
198
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
206
199
|
/**
|
|
207
200
|
* The maximum number of iterations for a loops
|
|
@@ -235,12 +228,6 @@
|
|
|
235
228
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
236
229
|
*/
|
|
237
230
|
var IMMEDIATE_TIME = 10;
|
|
238
|
-
/**
|
|
239
|
-
* The maximum length of the (generated) filename
|
|
240
|
-
*
|
|
241
|
-
* @public exported from `@promptbook/core`
|
|
242
|
-
*/
|
|
243
|
-
var MAX_FILENAME_LENGTH = 30;
|
|
244
231
|
/**
|
|
245
232
|
* Strategy for caching the intermediate results for knowledge sources
|
|
246
233
|
*
|
|
@@ -260,15 +247,6 @@
|
|
|
260
247
|
* @public exported from `@promptbook/core`
|
|
261
248
|
*/
|
|
262
249
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
263
|
-
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
264
|
-
/**
|
|
265
|
-
* Where to store the temporary downloads
|
|
266
|
-
*
|
|
267
|
-
* Note: When the folder does not exist, it is created recursively
|
|
268
|
-
*
|
|
269
|
-
* @public exported from `@promptbook/core`
|
|
270
|
-
*/
|
|
271
|
-
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
272
250
|
/**
|
|
273
251
|
* Where to store the scrape cache
|
|
274
252
|
*
|
|
@@ -963,18 +941,24 @@
|
|
|
963
941
|
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"}];
|
|
964
942
|
|
|
965
943
|
/**
|
|
966
|
-
*
|
|
944
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
967
945
|
*
|
|
968
946
|
* @public exported from `@promptbook/utils`
|
|
969
947
|
*/
|
|
970
|
-
function
|
|
971
|
-
|
|
972
|
-
|
|
948
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
949
|
+
try {
|
|
950
|
+
JSON.parse(value);
|
|
951
|
+
return true;
|
|
973
952
|
}
|
|
974
|
-
|
|
953
|
+
catch (error) {
|
|
954
|
+
if (!(error instanceof Error)) {
|
|
955
|
+
throw error;
|
|
956
|
+
}
|
|
957
|
+
if (error.message.includes('Unexpected token')) {
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
975
960
|
return false;
|
|
976
961
|
}
|
|
977
|
-
return /^.+@.+\..+$/.test(email);
|
|
978
962
|
}
|
|
979
963
|
|
|
980
964
|
/**
|
|
@@ -996,27 +980,6 @@
|
|
|
996
980
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
997
981
|
*/
|
|
998
982
|
|
|
999
|
-
/**
|
|
1000
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1001
|
-
*
|
|
1002
|
-
* @public exported from `@promptbook/utils`
|
|
1003
|
-
*/
|
|
1004
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1005
|
-
try {
|
|
1006
|
-
JSON.parse(value);
|
|
1007
|
-
return true;
|
|
1008
|
-
}
|
|
1009
|
-
catch (error) {
|
|
1010
|
-
if (!(error instanceof Error)) {
|
|
1011
|
-
throw error;
|
|
1012
|
-
}
|
|
1013
|
-
if (error.message.includes('Unexpected token')) {
|
|
1014
|
-
return false;
|
|
1015
|
-
}
|
|
1016
|
-
return false;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
983
|
/**
|
|
1021
984
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
1022
985
|
* 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.
|
|
@@ -1030,15 +993,6 @@
|
|
|
1030
993
|
if (isValidJsonString(pipelineString)) {
|
|
1031
994
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1032
995
|
}
|
|
1033
|
-
else if (isValidUrl(pipelineString)) {
|
|
1034
|
-
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1035
|
-
}
|
|
1036
|
-
else if (isValidFilePath(pipelineString)) {
|
|
1037
|
-
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1038
|
-
}
|
|
1039
|
-
else if (isValidEmail(pipelineString)) {
|
|
1040
|
-
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1041
|
-
}
|
|
1042
996
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1043
997
|
return pipelineString;
|
|
1044
998
|
}
|
|
@@ -2420,28 +2374,12 @@
|
|
|
2420
2374
|
/**
|
|
2421
2375
|
* Asserts that the execution of a Promptbook is successful
|
|
2422
2376
|
*
|
|
2423
|
-
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2424
|
-
*
|
|
2425
2377
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2426
2378
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2427
2379
|
* @public exported from `@promptbook/core`
|
|
2428
2380
|
*/
|
|
2429
2381
|
function assertsExecutionSuccessful(executionResult) {
|
|
2430
|
-
var
|
|
2431
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2432
|
-
try {
|
|
2433
|
-
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2434
|
-
var warning = warnings_1_1.value;
|
|
2435
|
-
console.warn(warning.message);
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2439
|
-
finally {
|
|
2440
|
-
try {
|
|
2441
|
-
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2442
|
-
}
|
|
2443
|
-
finally { if (e_1) throw e_1.error; }
|
|
2444
|
-
}
|
|
2382
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
2445
2383
|
if (isSuccessful === true) {
|
|
2446
2384
|
return;
|
|
2447
2385
|
}
|
|
@@ -3587,17 +3525,6 @@
|
|
|
3587
3525
|
return match ? match[1].toLowerCase() : null;
|
|
3588
3526
|
}
|
|
3589
3527
|
|
|
3590
|
-
/**
|
|
3591
|
-
* Convert mime type to file extension
|
|
3592
|
-
*
|
|
3593
|
-
* Note: If the mime type is invalid, `null` is returned
|
|
3594
|
-
*
|
|
3595
|
-
* @private within the repository
|
|
3596
|
-
*/
|
|
3597
|
-
function mimeTypeToExtension(value) {
|
|
3598
|
-
return mimeTypes.extension(value) || null;
|
|
3599
|
-
}
|
|
3600
|
-
|
|
3601
3528
|
/**
|
|
3602
3529
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3603
3530
|
*
|
|
@@ -3633,9 +3560,9 @@
|
|
|
3633
3560
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3634
3561
|
var _a;
|
|
3635
3562
|
return __awaiter(this, void 0, void 0, function () {
|
|
3636
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType,
|
|
3637
|
-
return __generator(this, function (
|
|
3638
|
-
switch (
|
|
3563
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3564
|
+
return __generator(this, function (_f) {
|
|
3565
|
+
switch (_f.label) {
|
|
3639
3566
|
case 0:
|
|
3640
3567
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3641
3568
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3644,76 +3571,54 @@
|
|
|
3644
3571
|
if (!name) {
|
|
3645
3572
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3646
3573
|
}
|
|
3647
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3574
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
|
|
3648
3575
|
url = knowledgeSourceContent;
|
|
3649
3576
|
return [4 /*yield*/, fetch(url)];
|
|
3650
3577
|
case 1:
|
|
3651
|
-
response_1 =
|
|
3578
|
+
response_1 = _f.sent();
|
|
3652
3579
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
}
|
|
3677
|
-
});
|
|
3580
|
+
return [2 /*return*/, {
|
|
3581
|
+
source: name,
|
|
3582
|
+
filename: null,
|
|
3583
|
+
url: url,
|
|
3584
|
+
mimeType: mimeType,
|
|
3585
|
+
/*
|
|
3586
|
+
TODO: [🥽]
|
|
3587
|
+
> async asBlob() {
|
|
3588
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3589
|
+
> const content = await response.blob();
|
|
3590
|
+
> return content;
|
|
3591
|
+
> },
|
|
3592
|
+
*/
|
|
3593
|
+
asJson: function () {
|
|
3594
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3595
|
+
var content;
|
|
3596
|
+
return __generator(this, function (_a) {
|
|
3597
|
+
switch (_a.label) {
|
|
3598
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3599
|
+
case 1:
|
|
3600
|
+
content = _a.sent();
|
|
3601
|
+
return [2 /*return*/, content];
|
|
3602
|
+
}
|
|
3678
3603
|
});
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
}
|
|
3604
|
+
});
|
|
3605
|
+
},
|
|
3606
|
+
asText: function () {
|
|
3607
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3608
|
+
var content;
|
|
3609
|
+
return __generator(this, function (_a) {
|
|
3610
|
+
switch (_a.label) {
|
|
3611
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3612
|
+
case 1:
|
|
3613
|
+
content = _a.sent();
|
|
3614
|
+
return [2 /*return*/, content];
|
|
3615
|
+
}
|
|
3691
3616
|
});
|
|
3692
|
-
}
|
|
3693
|
-
}
|
|
3694
|
-
|
|
3695
|
-
basename = url.split('/').pop() || titleToName(url);
|
|
3696
|
-
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3697
|
-
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3698
|
-
filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
|
|
3699
|
-
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3617
|
+
});
|
|
3618
|
+
},
|
|
3619
|
+
}];
|
|
3700
3620
|
case 2:
|
|
3701
|
-
|
|
3702
|
-
_g = (_f = Buffer).from;
|
|
3703
|
-
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3704
|
-
case 3:
|
|
3705
|
-
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3706
|
-
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3707
|
-
throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
|
|
3708
|
-
}
|
|
3709
|
-
return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
|
|
3710
|
-
case 4:
|
|
3711
|
-
_h.sent();
|
|
3712
|
-
// TODO: [💵] Check the file security
|
|
3713
|
-
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3714
|
-
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3715
|
-
case 5:
|
|
3716
|
-
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3621
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
|
|
3717
3622
|
if (tools.fs === undefined) {
|
|
3718
3623
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3719
3624
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3726,8 +3631,8 @@
|
|
|
3726
3631
|
fileExtension = getFileExtension(filename_1);
|
|
3727
3632
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3728
3633
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3729
|
-
case
|
|
3730
|
-
if (!(
|
|
3634
|
+
case 3:
|
|
3635
|
+
if (!(_f.sent())) {
|
|
3731
3636
|
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(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
3732
3637
|
}
|
|
3733
3638
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3773,7 +3678,7 @@
|
|
|
3773
3678
|
});
|
|
3774
3679
|
},
|
|
3775
3680
|
}];
|
|
3776
|
-
case
|
|
3681
|
+
case 4: return [2 /*return*/, {
|
|
3777
3682
|
source: name,
|
|
3778
3683
|
filename: null,
|
|
3779
3684
|
url: null,
|
|
@@ -6329,7 +6234,7 @@
|
|
|
6329
6234
|
className: 'MarkitdownScraper',
|
|
6330
6235
|
mimeTypes: [
|
|
6331
6236
|
'application/pdf',
|
|
6332
|
-
// TODO:
|
|
6237
|
+
// TODO: Make priority for scrapers and than allow all mime types here:
|
|
6333
6238
|
// 'text/html',
|
|
6334
6239
|
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
6335
6240
|
],
|
|
@@ -6365,10 +6270,10 @@
|
|
|
6365
6270
|
this.tools = tools;
|
|
6366
6271
|
this.options = options;
|
|
6367
6272
|
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
6368
|
-
// Note: Module `markitdown-ts` has no types available, so it is imported using `require`
|
|
6369
6273
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6370
6274
|
var MarkItDown = require('markitdown-ts').MarkItDown;
|
|
6371
|
-
// <- TODO:
|
|
6275
|
+
// <- TODO: !!! Use Markitdown directly not through this package
|
|
6276
|
+
// <- Note: !!!!!!!
|
|
6372
6277
|
this.markitdown = new MarkItDown();
|
|
6373
6278
|
}
|
|
6374
6279
|
Object.defineProperty(MarkitdownScraper.prototype, "metadata", {
|
|
@@ -6413,12 +6318,12 @@
|
|
|
6413
6318
|
case 2:
|
|
6414
6319
|
if (!!(_f.sent())) return [3 /*break*/, 5];
|
|
6415
6320
|
src = source.filename || source.url || null;
|
|
6416
|
-
|
|
6321
|
+
console.log('!!!', { src: src, source: source, cacheFilehandler: cacheFilehandler });
|
|
6417
6322
|
if (src === null) {
|
|
6418
6323
|
throw new UnexpectedError('Source has no filename or url');
|
|
6419
6324
|
}
|
|
6420
6325
|
return [4 /*yield*/, this.markitdown.convert(src, {
|
|
6421
|
-
// TODO: Pass when sacraping Youtube
|
|
6326
|
+
// TODO: !!!!!! Pass when sacraping Youtube
|
|
6422
6327
|
// enableYoutubeTranscript: true,
|
|
6423
6328
|
// youtubeTranscriptLanguage: 'en',
|
|
6424
6329
|
})];
|
|
@@ -6426,12 +6331,11 @@
|
|
|
6426
6331
|
result = _f.sent();
|
|
6427
6332
|
if (result === null || result === undefined) {
|
|
6428
6333
|
throw new Error("Markitdown could not convert the \"".concat(source.source, "\""));
|
|
6429
|
-
// <- TODO:
|
|
6334
|
+
// <- TODO: !!! Make MarkitdownError
|
|
6430
6335
|
}
|
|
6431
|
-
|
|
6336
|
+
console.log('!!!', { result: result, cacheFilehandler: cacheFilehandler });
|
|
6432
6337
|
return [4 /*yield*/, this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content)];
|
|
6433
6338
|
case 4:
|
|
6434
|
-
// console.log('!!', { result, cacheFilehandler });
|
|
6435
6339
|
_f.sent();
|
|
6436
6340
|
_f.label = 5;
|
|
6437
6341
|
case 5: return [2 /*return*/, cacheFilehandler];
|