@promptbook/cli 0.84.0-0 → 0.84.0-11
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 +1 -0
- package/esm/index.es.js +664 -221
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +8 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
- package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
- package/esm/typings/src/constants.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +5 -0
- package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
- package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
- package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/package.json +3 -2
- package/umd/index.umd.js +670 -222
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('waitasecond'), require('path'), require('fs/promises'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('mime-types'), require('child_process'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'waitasecond', 'path', 'fs/promises', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'mime-types', 'child_process', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.spaceTrim, global.waitasecond, global.path, global.promises, global.hexEncoder, global.sha256, global.dotenv, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.mimeTypes, global.child_process, global.
|
|
5
|
-
})(this, (function (exports, colors, commander, spaceTrim, waitasecond, path, promises, hexEncoder, sha256, dotenv, prettier, parserHtml, papaparse, cryptoJs, mimeTypes, child_process,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('spacetrim'), require('waitasecond'), require('path'), require('fs/promises'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('dotenv'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('mime-types'), require('child_process'), require('glob-promise'), require('prompts'), require('moment'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai'), require('@mozilla/readability'), require('jsdom'), require('showdown')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'spacetrim', 'waitasecond', 'path', 'fs/promises', 'crypto-js/enc-hex', 'crypto-js/sha256', 'dotenv', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'mime-types', 'child_process', 'glob-promise', 'prompts', 'moment', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai', '@mozilla/readability', 'jsdom', 'showdown'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.spaceTrim, global.waitasecond, global.path, global.promises, global.hexEncoder, global.sha256, global.dotenv, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.mimeTypes, global.child_process, global.glob, global.prompts, global.moment, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI, global.readability, global.jsdom, global.showdown));
|
|
5
|
+
})(this, (function (exports, colors, commander, spaceTrim, waitasecond, path, promises, hexEncoder, sha256, dotenv, prettier, parserHtml, papaparse, cryptoJs, mimeTypes, child_process, glob, prompts, moment, socket_ioClient, Anthropic, openai, OpenAI, readability, jsdom, showdown) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* @generated
|
|
52
52
|
* @see https://github.com/webgptorg/promptbook
|
|
53
53
|
*/
|
|
54
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
54
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
|
|
55
55
|
/**
|
|
56
56
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
57
57
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -215,7 +215,7 @@
|
|
|
215
215
|
*
|
|
216
216
|
* @public exported from `@promptbook/core`
|
|
217
217
|
*/
|
|
218
|
-
var ADMIN_EMAIL = '
|
|
218
|
+
var ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
219
219
|
/**
|
|
220
220
|
* Name of the responsible person for the Promptbook on GitHub
|
|
221
221
|
*
|
|
@@ -825,7 +825,7 @@
|
|
|
825
825
|
*
|
|
826
826
|
* @private within the repository
|
|
827
827
|
*/
|
|
828
|
-
var REPLACING_NONCE = '
|
|
828
|
+
var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
829
829
|
/**
|
|
830
830
|
* @@@
|
|
831
831
|
*
|
|
@@ -1928,7 +1928,7 @@
|
|
|
1928
1928
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1929
1929
|
__extends(NotYetImplementedError, _super);
|
|
1930
1930
|
function NotYetImplementedError(message) {
|
|
1931
|
-
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on
|
|
1931
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
|
|
1932
1932
|
_this.name = 'NotYetImplementedError';
|
|
1933
1933
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1934
1934
|
return _this;
|
|
@@ -2803,24 +2803,18 @@
|
|
|
2803
2803
|
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"}];
|
|
2804
2804
|
|
|
2805
2805
|
/**
|
|
2806
|
-
*
|
|
2806
|
+
* Checks if value is valid email
|
|
2807
2807
|
*
|
|
2808
2808
|
* @public exported from `@promptbook/utils`
|
|
2809
2809
|
*/
|
|
2810
|
-
function
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
return true;
|
|
2810
|
+
function isValidEmail(email) {
|
|
2811
|
+
if (typeof email !== 'string') {
|
|
2812
|
+
return false;
|
|
2814
2813
|
}
|
|
2815
|
-
|
|
2816
|
-
if (!(error instanceof Error)) {
|
|
2817
|
-
throw error;
|
|
2818
|
-
}
|
|
2819
|
-
if (error.message.includes('Unexpected token')) {
|
|
2820
|
-
return false;
|
|
2821
|
-
}
|
|
2814
|
+
if (email.split('\n').length > 1) {
|
|
2822
2815
|
return false;
|
|
2823
2816
|
}
|
|
2817
|
+
return /^.+@.+\..+$/.test(email);
|
|
2824
2818
|
}
|
|
2825
2819
|
|
|
2826
2820
|
/**
|
|
@@ -2842,6 +2836,27 @@
|
|
|
2842
2836
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
2843
2837
|
*/
|
|
2844
2838
|
|
|
2839
|
+
/**
|
|
2840
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2841
|
+
*
|
|
2842
|
+
* @public exported from `@promptbook/utils`
|
|
2843
|
+
*/
|
|
2844
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
2845
|
+
try {
|
|
2846
|
+
JSON.parse(value);
|
|
2847
|
+
return true;
|
|
2848
|
+
}
|
|
2849
|
+
catch (error) {
|
|
2850
|
+
if (!(error instanceof Error)) {
|
|
2851
|
+
throw error;
|
|
2852
|
+
}
|
|
2853
|
+
if (error.message.includes('Unexpected token')) {
|
|
2854
|
+
return false;
|
|
2855
|
+
}
|
|
2856
|
+
return false;
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2845
2860
|
/**
|
|
2846
2861
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
2847
2862
|
* 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.
|
|
@@ -2855,6 +2870,15 @@
|
|
|
2855
2870
|
if (isValidJsonString(pipelineString)) {
|
|
2856
2871
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
2857
2872
|
}
|
|
2873
|
+
else if (isValidUrl(pipelineString)) {
|
|
2874
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
2875
|
+
}
|
|
2876
|
+
else if (isValidFilePath(pipelineString)) {
|
|
2877
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
2878
|
+
}
|
|
2879
|
+
else if (isValidEmail(pipelineString)) {
|
|
2880
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
2881
|
+
}
|
|
2858
2882
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
2859
2883
|
return pipelineString;
|
|
2860
2884
|
}
|
|
@@ -3927,12 +3951,28 @@
|
|
|
3927
3951
|
/**
|
|
3928
3952
|
* Asserts that the execution of a Promptbook is successful
|
|
3929
3953
|
*
|
|
3954
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
3955
|
+
*
|
|
3930
3956
|
* @param executionResult - The partial result of the Promptbook execution
|
|
3931
3957
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
3932
3958
|
* @public exported from `@promptbook/core`
|
|
3933
3959
|
*/
|
|
3934
3960
|
function assertsExecutionSuccessful(executionResult) {
|
|
3935
|
-
var
|
|
3961
|
+
var e_1, _a;
|
|
3962
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
3963
|
+
try {
|
|
3964
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
3965
|
+
var warning = warnings_1_1.value;
|
|
3966
|
+
console.warn(warning.message);
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3970
|
+
finally {
|
|
3971
|
+
try {
|
|
3972
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
3973
|
+
}
|
|
3974
|
+
finally { if (e_1) throw e_1.error; }
|
|
3975
|
+
}
|
|
3936
3976
|
if (isSuccessful === true) {
|
|
3937
3977
|
return;
|
|
3938
3978
|
}
|
|
@@ -10405,30 +10445,187 @@
|
|
|
10405
10445
|
* TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
|
|
10406
10446
|
*/
|
|
10407
10447
|
|
|
10408
|
-
|
|
10409
|
-
|
|
10448
|
+
/**
|
|
10449
|
+
* Normalize options for `execCommand` and `execCommands`
|
|
10450
|
+
*
|
|
10451
|
+
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
10452
|
+
*
|
|
10453
|
+
* @private internal utility of `execCommand` and `execCommands`
|
|
10454
|
+
*/
|
|
10455
|
+
function $execCommandNormalizeOptions(options) {
|
|
10456
|
+
var _a;
|
|
10457
|
+
var _b, _c, _d, _e;
|
|
10458
|
+
var command;
|
|
10459
|
+
var cwd;
|
|
10460
|
+
var crashOnError;
|
|
10461
|
+
var args = [];
|
|
10462
|
+
var timeout;
|
|
10463
|
+
var isVerbose;
|
|
10464
|
+
if (typeof options === 'string') {
|
|
10465
|
+
// TODO: [1] DRY default values
|
|
10466
|
+
command = options;
|
|
10467
|
+
cwd = process.cwd();
|
|
10468
|
+
crashOnError = true;
|
|
10469
|
+
timeout = Infinity; // <- TODO: [⏳]
|
|
10470
|
+
isVerbose = DEFAULT_IS_VERBOSE;
|
|
10471
|
+
}
|
|
10472
|
+
else {
|
|
10473
|
+
/*
|
|
10474
|
+
TODO:
|
|
10475
|
+
if ((options as any).commands !== undefined) {
|
|
10476
|
+
commands = (options as any).commands;
|
|
10477
|
+
} else {
|
|
10478
|
+
commands = [(options as any).command];
|
|
10479
|
+
}
|
|
10480
|
+
*/
|
|
10481
|
+
// TODO: [1] DRY default values
|
|
10482
|
+
command = options.command;
|
|
10483
|
+
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
10484
|
+
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
10485
|
+
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
10486
|
+
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
10487
|
+
}
|
|
10488
|
+
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
10489
|
+
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
10490
|
+
.map(function (_a) {
|
|
10491
|
+
var _b = __read(_a, 1), match = _b[0];
|
|
10492
|
+
return match;
|
|
10493
|
+
})
|
|
10494
|
+
.filter(function (arg) { return arg !== ''; });
|
|
10495
|
+
if (_.length > 1) {
|
|
10496
|
+
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
10497
|
+
}
|
|
10498
|
+
if (options.args) {
|
|
10499
|
+
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
10500
|
+
}
|
|
10501
|
+
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
10502
|
+
if (['ts-node'].includes(humanReadableCommand)) {
|
|
10503
|
+
humanReadableCommand += " ".concat(args[1]);
|
|
10504
|
+
}
|
|
10505
|
+
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
10506
|
+
command = "".concat(command, ".cmd");
|
|
10507
|
+
}
|
|
10508
|
+
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
10509
|
+
}
|
|
10510
|
+
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
10511
|
+
|
|
10512
|
+
/**
|
|
10513
|
+
* Run one command in a shell
|
|
10514
|
+
*
|
|
10515
|
+
*
|
|
10516
|
+
* Note: There are 2 similar functions in the codebase:
|
|
10517
|
+
* - `$execCommand` which runs a single command
|
|
10518
|
+
* - `$execCommands` which runs multiple commands
|
|
10519
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
10520
|
+
*
|
|
10521
|
+
* @public exported from `@promptbook/node`
|
|
10522
|
+
*/
|
|
10523
|
+
function $execCommand(options) {
|
|
10524
|
+
if (!$isRunningInNode()) {
|
|
10525
|
+
throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
|
|
10526
|
+
}
|
|
10527
|
+
return new Promise(function (resolve, reject) {
|
|
10528
|
+
// eslint-disable-next-line prefer-const
|
|
10529
|
+
var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
10530
|
+
if (timeout !== Infinity) {
|
|
10531
|
+
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
10532
|
+
waitasecond.forTime(timeout).then(function () {
|
|
10533
|
+
if (crashOnError) {
|
|
10534
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
|
|
10535
|
+
}
|
|
10536
|
+
else {
|
|
10537
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
|
|
10538
|
+
resolve('Command exceeded time limit');
|
|
10539
|
+
}
|
|
10540
|
+
});
|
|
10541
|
+
}
|
|
10542
|
+
if (isVerbose) {
|
|
10543
|
+
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
10544
|
+
}
|
|
10545
|
+
try {
|
|
10546
|
+
var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
|
|
10547
|
+
if (isVerbose) {
|
|
10548
|
+
commandProcess.on('message', function (message) {
|
|
10549
|
+
console.info({ message: message });
|
|
10550
|
+
});
|
|
10551
|
+
}
|
|
10552
|
+
var output_1 = [];
|
|
10553
|
+
commandProcess.stdout.on('data', function (stdout) {
|
|
10554
|
+
output_1.push(stdout.toString());
|
|
10555
|
+
if (isVerbose) {
|
|
10556
|
+
console.info(stdout.toString());
|
|
10557
|
+
}
|
|
10558
|
+
});
|
|
10559
|
+
commandProcess.stderr.on('data', function (stderr) {
|
|
10560
|
+
output_1.push(stderr.toString());
|
|
10561
|
+
if (isVerbose && stderr.toString().trim()) {
|
|
10562
|
+
console.warn(stderr.toString());
|
|
10563
|
+
}
|
|
10564
|
+
});
|
|
10565
|
+
var finishWithCode = function (code) {
|
|
10566
|
+
if (code !== 0) {
|
|
10567
|
+
if (crashOnError) {
|
|
10568
|
+
reject(new Error(output_1.join('\n').trim() ||
|
|
10569
|
+
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
10570
|
+
}
|
|
10571
|
+
else {
|
|
10572
|
+
if (isVerbose) {
|
|
10573
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
10574
|
+
}
|
|
10575
|
+
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
10576
|
+
}
|
|
10577
|
+
}
|
|
10578
|
+
else {
|
|
10579
|
+
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
10580
|
+
}
|
|
10581
|
+
};
|
|
10582
|
+
commandProcess.on('close', finishWithCode);
|
|
10583
|
+
commandProcess.on('exit', finishWithCode);
|
|
10584
|
+
commandProcess.on('disconnect', function () {
|
|
10585
|
+
// Note: Unexpected disconnection should always result in rejection
|
|
10586
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
|
|
10587
|
+
});
|
|
10588
|
+
commandProcess.on('error', function (error) {
|
|
10589
|
+
if (crashOnError) {
|
|
10590
|
+
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
10591
|
+
}
|
|
10592
|
+
else {
|
|
10593
|
+
if (isVerbose) {
|
|
10594
|
+
console.warn(error);
|
|
10595
|
+
}
|
|
10596
|
+
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
10597
|
+
}
|
|
10598
|
+
});
|
|
10599
|
+
}
|
|
10600
|
+
catch (error) {
|
|
10601
|
+
// Note: Unexpected error in sync code should always result in rejection
|
|
10602
|
+
reject(error);
|
|
10603
|
+
}
|
|
10604
|
+
});
|
|
10605
|
+
}
|
|
10606
|
+
/**
|
|
10607
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
10608
|
+
*/
|
|
10609
|
+
|
|
10410
10610
|
/**
|
|
10411
10611
|
* @@@
|
|
10412
10612
|
*
|
|
10413
10613
|
* @private within the repository
|
|
10414
10614
|
*/
|
|
10415
10615
|
function locateAppOnLinux(_a) {
|
|
10416
|
-
var
|
|
10616
|
+
var linuxWhich = _a.linuxWhich;
|
|
10417
10617
|
return __awaiter(this, void 0, void 0, function () {
|
|
10418
|
-
var
|
|
10419
|
-
return __generator(this, function (
|
|
10420
|
-
switch (
|
|
10618
|
+
var result, error_1;
|
|
10619
|
+
return __generator(this, function (_b) {
|
|
10620
|
+
switch (_b.label) {
|
|
10421
10621
|
case 0:
|
|
10422
|
-
|
|
10423
|
-
return [4 /*yield*/,
|
|
10622
|
+
_b.trys.push([0, 2, , 3]);
|
|
10623
|
+
return [4 /*yield*/, $execCommand({ crashOnError: true, command: "which ".concat(linuxWhich) })];
|
|
10424
10624
|
case 1:
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
return [2 /*return*/, stdout.trim()];
|
|
10428
|
-
}
|
|
10429
|
-
throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
|
|
10625
|
+
result = _b.sent();
|
|
10626
|
+
return [2 /*return*/, result.trim()];
|
|
10430
10627
|
case 2:
|
|
10431
|
-
error_1 =
|
|
10628
|
+
error_1 = _b.sent();
|
|
10432
10629
|
if (!(error_1 instanceof Error)) {
|
|
10433
10630
|
throw error_1;
|
|
10434
10631
|
}
|
|
@@ -10475,43 +10672,41 @@
|
|
|
10475
10672
|
// @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
|
|
10476
10673
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10477
10674
|
var userhome = require('userhome');
|
|
10478
|
-
// Note: We want to use the `exec` as async function
|
|
10479
|
-
var exec = util.promisify(child_process.exec);
|
|
10480
10675
|
/**
|
|
10481
10676
|
* @@@
|
|
10482
10677
|
*
|
|
10483
10678
|
* @private within the repository
|
|
10484
10679
|
*/
|
|
10485
10680
|
function locateAppOnMacOs(_a) {
|
|
10486
|
-
var
|
|
10681
|
+
var macOsName = _a.macOsName;
|
|
10487
10682
|
return __awaiter(this, void 0, void 0, function () {
|
|
10488
|
-
var toExec, regPath, altPath,
|
|
10489
|
-
return __generator(this, function (
|
|
10490
|
-
switch (
|
|
10683
|
+
var toExec, regPath, altPath, result, error_1;
|
|
10684
|
+
return __generator(this, function (_b) {
|
|
10685
|
+
switch (_b.label) {
|
|
10491
10686
|
case 0:
|
|
10492
|
-
|
|
10687
|
+
_b.trys.push([0, 6, , 7]);
|
|
10493
10688
|
toExec = "/Contents/MacOS/".concat(macOsName);
|
|
10494
10689
|
regPath = "/Applications/".concat(macOsName, ".app") + toExec;
|
|
10495
10690
|
altPath = userhome(regPath.slice(1));
|
|
10496
10691
|
return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
|
|
10497
10692
|
case 1:
|
|
10498
|
-
if (!
|
|
10693
|
+
if (!_b.sent()) return [3 /*break*/, 2];
|
|
10499
10694
|
return [2 /*return*/, regPath];
|
|
10500
10695
|
case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
|
|
10501
10696
|
case 3:
|
|
10502
|
-
if (
|
|
10697
|
+
if (_b.sent()) {
|
|
10503
10698
|
return [2 /*return*/, altPath];
|
|
10504
10699
|
}
|
|
10505
|
-
|
|
10506
|
-
case 4: return [4 /*yield*/,
|
|
10700
|
+
_b.label = 4;
|
|
10701
|
+
case 4: return [4 /*yield*/, $execCommand({
|
|
10702
|
+
crashOnError: true,
|
|
10703
|
+
command: "mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"),
|
|
10704
|
+
})];
|
|
10507
10705
|
case 5:
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
return [2 /*return*/, stdout.trim() + toExec];
|
|
10511
|
-
}
|
|
10512
|
-
throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
|
|
10706
|
+
result = _b.sent();
|
|
10707
|
+
return [2 /*return*/, result.trim() + toExec];
|
|
10513
10708
|
case 6:
|
|
10514
|
-
error_1 =
|
|
10709
|
+
error_1 = _b.sent();
|
|
10515
10710
|
if (!(error_1 instanceof Error)) {
|
|
10516
10711
|
throw error_1;
|
|
10517
10712
|
}
|
|
@@ -10612,7 +10807,7 @@
|
|
|
10612
10807
|
}
|
|
10613
10808
|
else if (process.platform === 'darwin') {
|
|
10614
10809
|
if (macOsName) {
|
|
10615
|
-
return locateAppOnMacOs({
|
|
10810
|
+
return locateAppOnMacOs({ macOsName: macOsName });
|
|
10616
10811
|
}
|
|
10617
10812
|
else {
|
|
10618
10813
|
throw new Error("".concat(appName, " is not available on macOS."));
|
|
@@ -10620,7 +10815,7 @@
|
|
|
10620
10815
|
}
|
|
10621
10816
|
else {
|
|
10622
10817
|
if (linuxWhich) {
|
|
10623
|
-
return locateAppOnLinux({
|
|
10818
|
+
return locateAppOnLinux({ linuxWhich: linuxWhich });
|
|
10624
10819
|
}
|
|
10625
10820
|
else {
|
|
10626
10821
|
throw new Error("".concat(appName, " is not available on Linux."));
|
|
@@ -15827,173 +16022,11 @@
|
|
|
15827
16022
|
*/
|
|
15828
16023
|
|
|
15829
16024
|
/**
|
|
15830
|
-
*
|
|
16025
|
+
* Create a filename for intermediate cache for scrapers
|
|
15831
16026
|
*
|
|
15832
|
-
* Note:
|
|
16027
|
+
* Note: It also checks if directory exists and creates it if not
|
|
15833
16028
|
*
|
|
15834
|
-
* @private internal utility
|
|
15835
|
-
*/
|
|
15836
|
-
function $execCommandNormalizeOptions(options) {
|
|
15837
|
-
var _a;
|
|
15838
|
-
var _b, _c, _d, _e;
|
|
15839
|
-
var command;
|
|
15840
|
-
var cwd;
|
|
15841
|
-
var crashOnError;
|
|
15842
|
-
var args = [];
|
|
15843
|
-
var timeout;
|
|
15844
|
-
var isVerbose;
|
|
15845
|
-
if (typeof options === 'string') {
|
|
15846
|
-
// TODO: [1] DRY default values
|
|
15847
|
-
command = options;
|
|
15848
|
-
cwd = process.cwd();
|
|
15849
|
-
crashOnError = true;
|
|
15850
|
-
timeout = Infinity; // <- TODO: [⏳]
|
|
15851
|
-
isVerbose = DEFAULT_IS_VERBOSE;
|
|
15852
|
-
}
|
|
15853
|
-
else {
|
|
15854
|
-
/*
|
|
15855
|
-
TODO:
|
|
15856
|
-
if ((options as any).commands !== undefined) {
|
|
15857
|
-
commands = (options as any).commands;
|
|
15858
|
-
} else {
|
|
15859
|
-
commands = [(options as any).command];
|
|
15860
|
-
}
|
|
15861
|
-
*/
|
|
15862
|
-
// TODO: [1] DRY default values
|
|
15863
|
-
command = options.command;
|
|
15864
|
-
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
15865
|
-
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
15866
|
-
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
15867
|
-
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
15868
|
-
}
|
|
15869
|
-
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
15870
|
-
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
15871
|
-
.map(function (_a) {
|
|
15872
|
-
var _b = __read(_a, 1), match = _b[0];
|
|
15873
|
-
return match;
|
|
15874
|
-
})
|
|
15875
|
-
.filter(function (arg) { return arg !== ''; });
|
|
15876
|
-
if (_.length > 1) {
|
|
15877
|
-
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
15878
|
-
}
|
|
15879
|
-
if (options.args) {
|
|
15880
|
-
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
15881
|
-
}
|
|
15882
|
-
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|
|
15883
|
-
if (['ts-node'].includes(humanReadableCommand)) {
|
|
15884
|
-
humanReadableCommand += " ".concat(args[1]);
|
|
15885
|
-
}
|
|
15886
|
-
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
15887
|
-
command = "".concat(command, ".cmd");
|
|
15888
|
-
}
|
|
15889
|
-
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
15890
|
-
}
|
|
15891
|
-
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
15892
|
-
|
|
15893
|
-
/**
|
|
15894
|
-
* Run one command in a shell
|
|
15895
|
-
*
|
|
15896
|
-
*
|
|
15897
|
-
* Note: There are 2 similar functions in the codebase:
|
|
15898
|
-
* - `$execCommand` which runs a single command
|
|
15899
|
-
* - `$execCommands` which runs multiple commands
|
|
15900
|
-
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
15901
|
-
*
|
|
15902
|
-
* @public exported from `@promptbook/node`
|
|
15903
|
-
*/
|
|
15904
|
-
function $execCommand(options) {
|
|
15905
|
-
if (!$isRunningInNode()) {
|
|
15906
|
-
throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
|
|
15907
|
-
}
|
|
15908
|
-
return new Promise(function (resolve, reject) {
|
|
15909
|
-
// eslint-disable-next-line prefer-const
|
|
15910
|
-
var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
15911
|
-
if (timeout !== Infinity) {
|
|
15912
|
-
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
15913
|
-
waitasecond.forTime(timeout).then(function () {
|
|
15914
|
-
if (crashOnError) {
|
|
15915
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
|
|
15916
|
-
}
|
|
15917
|
-
else {
|
|
15918
|
-
console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
|
|
15919
|
-
resolve('Command exceeded time limit');
|
|
15920
|
-
}
|
|
15921
|
-
});
|
|
15922
|
-
}
|
|
15923
|
-
if (isVerbose) {
|
|
15924
|
-
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
15925
|
-
}
|
|
15926
|
-
try {
|
|
15927
|
-
var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
|
|
15928
|
-
if (isVerbose) {
|
|
15929
|
-
commandProcess.on('message', function (message) {
|
|
15930
|
-
console.info({ message: message });
|
|
15931
|
-
});
|
|
15932
|
-
}
|
|
15933
|
-
var output_1 = [];
|
|
15934
|
-
commandProcess.stdout.on('data', function (stdout) {
|
|
15935
|
-
output_1.push(stdout.toString());
|
|
15936
|
-
if (isVerbose) {
|
|
15937
|
-
console.info(stdout.toString());
|
|
15938
|
-
}
|
|
15939
|
-
});
|
|
15940
|
-
commandProcess.stderr.on('data', function (stderr) {
|
|
15941
|
-
output_1.push(stderr.toString());
|
|
15942
|
-
if (isVerbose && stderr.toString().trim()) {
|
|
15943
|
-
console.warn(stderr.toString());
|
|
15944
|
-
}
|
|
15945
|
-
});
|
|
15946
|
-
var finishWithCode = function (code) {
|
|
15947
|
-
if (code !== 0) {
|
|
15948
|
-
if (crashOnError) {
|
|
15949
|
-
reject(new Error(output_1.join('\n').trim() ||
|
|
15950
|
-
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
15951
|
-
}
|
|
15952
|
-
else {
|
|
15953
|
-
if (isVerbose) {
|
|
15954
|
-
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
15955
|
-
}
|
|
15956
|
-
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
15957
|
-
}
|
|
15958
|
-
}
|
|
15959
|
-
else {
|
|
15960
|
-
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
15961
|
-
}
|
|
15962
|
-
};
|
|
15963
|
-
commandProcess.on('close', finishWithCode);
|
|
15964
|
-
commandProcess.on('exit', finishWithCode);
|
|
15965
|
-
commandProcess.on('disconnect', function () {
|
|
15966
|
-
// Note: Unexpected disconnection should always result in rejection
|
|
15967
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
|
|
15968
|
-
});
|
|
15969
|
-
commandProcess.on('error', function (error) {
|
|
15970
|
-
if (crashOnError) {
|
|
15971
|
-
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
15972
|
-
}
|
|
15973
|
-
else {
|
|
15974
|
-
if (isVerbose) {
|
|
15975
|
-
console.warn(error);
|
|
15976
|
-
}
|
|
15977
|
-
resolve(spaceTrim.spaceTrim(output_1.join('\n')));
|
|
15978
|
-
}
|
|
15979
|
-
});
|
|
15980
|
-
}
|
|
15981
|
-
catch (error) {
|
|
15982
|
-
// Note: Unexpected error in sync code should always result in rejection
|
|
15983
|
-
reject(error);
|
|
15984
|
-
}
|
|
15985
|
-
});
|
|
15986
|
-
}
|
|
15987
|
-
/**
|
|
15988
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
15989
|
-
*/
|
|
15990
|
-
|
|
15991
|
-
/**
|
|
15992
|
-
* Create a filename for intermediate cache for scrapers
|
|
15993
|
-
*
|
|
15994
|
-
* Note: It also checks if directory exists and creates it if not
|
|
15995
|
-
*
|
|
15996
|
-
* @private as internal utility for scrapers
|
|
16029
|
+
* @private as internal utility for scrapers
|
|
15997
16030
|
*/
|
|
15998
16031
|
function getScraperIntermediateSource(source, options) {
|
|
15999
16032
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -16258,6 +16291,207 @@
|
|
|
16258
16291
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
16259
16292
|
*/
|
|
16260
16293
|
|
|
16294
|
+
/**
|
|
16295
|
+
* Metadata of the scraper
|
|
16296
|
+
*
|
|
16297
|
+
* @private within the scraper directory
|
|
16298
|
+
*/
|
|
16299
|
+
var boilerplateScraperMetadata = $deepFreeze({
|
|
16300
|
+
title: 'Boilerplate scraper',
|
|
16301
|
+
packageName: '@promptbook/boilerplate',
|
|
16302
|
+
className: 'BoilerplateScraper',
|
|
16303
|
+
mimeTypes: [
|
|
16304
|
+
'@@@/@@@',
|
|
16305
|
+
// <- TODO: @@@ Add compatible mime types with Boilerplate scraper
|
|
16306
|
+
],
|
|
16307
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@@',
|
|
16308
|
+
isAvilableInBrowser: false,
|
|
16309
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16310
|
+
requiredExecutables: [
|
|
16311
|
+
/* @@@ 'Pandoc' */
|
|
16312
|
+
],
|
|
16313
|
+
}); /* <- Note: [🤛] */
|
|
16314
|
+
/**
|
|
16315
|
+
* Registration of known scraper metadata
|
|
16316
|
+
*
|
|
16317
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16318
|
+
*
|
|
16319
|
+
* @public exported from `@promptbook/core`
|
|
16320
|
+
* @public exported from `@promptbook/wizzard`
|
|
16321
|
+
* @public exported from `@promptbook/cli`
|
|
16322
|
+
*/
|
|
16323
|
+
var _BoilerplateScraperMetadataRegistration = $scrapersMetadataRegister.register(boilerplateScraperMetadata);
|
|
16324
|
+
/**
|
|
16325
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16326
|
+
*/
|
|
16327
|
+
|
|
16328
|
+
/**
|
|
16329
|
+
* Scraper of @@@ files
|
|
16330
|
+
*
|
|
16331
|
+
* @see `documentationUrl` for more details
|
|
16332
|
+
* @public exported from `@promptbook/boilerplate`
|
|
16333
|
+
*/
|
|
16334
|
+
var BoilerplateScraper = /** @class */ (function () {
|
|
16335
|
+
function BoilerplateScraper(tools, options) {
|
|
16336
|
+
this.tools = tools;
|
|
16337
|
+
this.options = options;
|
|
16338
|
+
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
16339
|
+
}
|
|
16340
|
+
Object.defineProperty(BoilerplateScraper.prototype, "metadata", {
|
|
16341
|
+
/**
|
|
16342
|
+
* Metadata of the scraper which includes title, mime types, etc.
|
|
16343
|
+
*/
|
|
16344
|
+
get: function () {
|
|
16345
|
+
return boilerplateScraperMetadata;
|
|
16346
|
+
},
|
|
16347
|
+
enumerable: false,
|
|
16348
|
+
configurable: true
|
|
16349
|
+
});
|
|
16350
|
+
/**
|
|
16351
|
+
* Convert the `.@@@` to `.md` file and returns intermediate source
|
|
16352
|
+
*
|
|
16353
|
+
* Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
|
|
16354
|
+
*/
|
|
16355
|
+
BoilerplateScraper.prototype.$convert = function (source) {
|
|
16356
|
+
var _a;
|
|
16357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16358
|
+
var _b, _c, rootDirname, _d, cacheDirname, _e, intermediateFilesStrategy, _f, isVerbose, extension, cacheFilehandler, command_1;
|
|
16359
|
+
return __generator(this, function (_g) {
|
|
16360
|
+
switch (_g.label) {
|
|
16361
|
+
case 0:
|
|
16362
|
+
_b = this.options, _c = _b.rootDirname, rootDirname = _c === void 0 ? process.cwd() : _c, _d = _b.cacheDirname, cacheDirname = _d === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _d, _e = _b.intermediateFilesStrategy, intermediateFilesStrategy = _e === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _e, _f = _b.isVerbose, isVerbose = _f === void 0 ? DEFAULT_IS_VERBOSE : _f;
|
|
16363
|
+
// TODO: @@@ Preserve or delete
|
|
16364
|
+
if (!$isRunningInNode()) {
|
|
16365
|
+
throw new KnowledgeScrapeError('BoilerplateScraper is only supported in Node environment');
|
|
16366
|
+
}
|
|
16367
|
+
// TODO: @@@ Preserve or delete
|
|
16368
|
+
if (this.tools.fs === undefined) {
|
|
16369
|
+
throw new EnvironmentMismatchError('Can not scrape boilerplates without filesystem tools');
|
|
16370
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
16371
|
+
}
|
|
16372
|
+
// TODO: @@@ Preserve, delete or modify
|
|
16373
|
+
if (((_a = this.tools.executables) === null || _a === void 0 ? void 0 : _a.pandocPath) === undefined) {
|
|
16374
|
+
throw new MissingToolsError('Pandoc is required for scraping .docx files');
|
|
16375
|
+
}
|
|
16376
|
+
// TODO: @@@ Preserve, delete or modify
|
|
16377
|
+
if (source.filename === null) {
|
|
16378
|
+
// TODO: [🧠] Maybe save file as temporary
|
|
16379
|
+
throw new KnowledgeScrapeError('When parsing .@@@ file, it must be real file in the file system');
|
|
16380
|
+
}
|
|
16381
|
+
extension = getFileExtension(source.filename);
|
|
16382
|
+
return [4 /*yield*/, getScraperIntermediateSource(source, {
|
|
16383
|
+
rootDirname: rootDirname,
|
|
16384
|
+
cacheDirname: cacheDirname,
|
|
16385
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
16386
|
+
extension: 'md',
|
|
16387
|
+
isVerbose: isVerbose,
|
|
16388
|
+
})];
|
|
16389
|
+
case 1:
|
|
16390
|
+
cacheFilehandler = _g.sent();
|
|
16391
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
16392
|
+
case 2:
|
|
16393
|
+
if (!!(_g.sent())) return [3 /*break*/, 5];
|
|
16394
|
+
command_1 = "\"".concat(this.tools.executables.pandocPath, "\" -f ").concat(extension, " -t markdown \"").concat(source.filename, "\" -o \"").concat(cacheFilehandler.filename, "\"");
|
|
16395
|
+
return [4 /*yield*/, $execCommand(command_1)];
|
|
16396
|
+
case 3:
|
|
16397
|
+
_g.sent();
|
|
16398
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
16399
|
+
case 4:
|
|
16400
|
+
// Note: [0]
|
|
16401
|
+
if (!(_g.sent())) {
|
|
16402
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
16403
|
+
}
|
|
16404
|
+
_g.label = 5;
|
|
16405
|
+
case 5: return [2 /*return*/, cacheFilehandler];
|
|
16406
|
+
}
|
|
16407
|
+
});
|
|
16408
|
+
});
|
|
16409
|
+
};
|
|
16410
|
+
/**
|
|
16411
|
+
* Scrapes the docx file and returns the knowledge pieces or `null` if it can't scrape it
|
|
16412
|
+
*/
|
|
16413
|
+
BoilerplateScraper.prototype.scrape = function (source) {
|
|
16414
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16415
|
+
var cacheFilehandler, markdownSource, knowledge;
|
|
16416
|
+
return __generator(this, function (_a) {
|
|
16417
|
+
switch (_a.label) {
|
|
16418
|
+
case 0: return [4 /*yield*/, this.$convert(source)];
|
|
16419
|
+
case 1:
|
|
16420
|
+
cacheFilehandler = _a.sent();
|
|
16421
|
+
markdownSource = {
|
|
16422
|
+
source: source.source,
|
|
16423
|
+
filename: cacheFilehandler.filename,
|
|
16424
|
+
url: null,
|
|
16425
|
+
mimeType: 'text/markdown',
|
|
16426
|
+
asText: function () {
|
|
16427
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16428
|
+
return __generator(this, function (_a) {
|
|
16429
|
+
switch (_a.label) {
|
|
16430
|
+
case 0: return [4 /*yield*/, promises.readFile(cacheFilehandler.filename, 'utf-8')];
|
|
16431
|
+
case 1:
|
|
16432
|
+
// Note: [0] In $convert we check that the file exists
|
|
16433
|
+
return [2 /*return*/, _a.sent()];
|
|
16434
|
+
}
|
|
16435
|
+
});
|
|
16436
|
+
});
|
|
16437
|
+
},
|
|
16438
|
+
asJson: function () {
|
|
16439
|
+
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
16440
|
+
},
|
|
16441
|
+
/*
|
|
16442
|
+
TODO: [🥽]
|
|
16443
|
+
> asBlob() {
|
|
16444
|
+
> throw new UnexpectedError(
|
|
16445
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
16446
|
+
> );
|
|
16447
|
+
> },
|
|
16448
|
+
*/
|
|
16449
|
+
};
|
|
16450
|
+
knowledge = this.markdownScraper.scrape(markdownSource);
|
|
16451
|
+
return [4 /*yield*/, cacheFilehandler.destroy()];
|
|
16452
|
+
case 2:
|
|
16453
|
+
_a.sent();
|
|
16454
|
+
return [2 /*return*/, knowledge];
|
|
16455
|
+
}
|
|
16456
|
+
});
|
|
16457
|
+
});
|
|
16458
|
+
};
|
|
16459
|
+
return BoilerplateScraper;
|
|
16460
|
+
}());
|
|
16461
|
+
/**
|
|
16462
|
+
* TODO: [👣] Converted documents can act as cached items - there is no need to run conversion each time
|
|
16463
|
+
* TODO: [🪂] Do it in parallel
|
|
16464
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
16465
|
+
* @@@ Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
16466
|
+
*/
|
|
16467
|
+
|
|
16468
|
+
/**
|
|
16469
|
+
* Constructor of `BoilerplateScraper`
|
|
16470
|
+
*
|
|
16471
|
+
* @public exported from `@promptbook/boilerplate`
|
|
16472
|
+
*/
|
|
16473
|
+
var createBoilerplateScraper = Object.assign(function (tools, options) {
|
|
16474
|
+
return new BoilerplateScraper(tools, options);
|
|
16475
|
+
}, boilerplateScraperMetadata); /* <- Note: [🤛] */
|
|
16476
|
+
/**
|
|
16477
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
16478
|
+
*/
|
|
16479
|
+
|
|
16480
|
+
/**
|
|
16481
|
+
* Registration of known scraper
|
|
16482
|
+
*
|
|
16483
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16484
|
+
*
|
|
16485
|
+
* @public exported from `@promptbook/boilerplate`
|
|
16486
|
+
* @public exported from `@promptbook/wizzard`
|
|
16487
|
+
* @public exported from `@promptbook/cli`
|
|
16488
|
+
*/
|
|
16489
|
+
var _BoilerplateScraperRegistration = $scrapersRegister.register(createBoilerplateScraper);
|
|
16490
|
+
/**
|
|
16491
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
16492
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16493
|
+
*/
|
|
16494
|
+
|
|
16261
16495
|
/**
|
|
16262
16496
|
* Metadata of the scraper
|
|
16263
16497
|
*
|
|
@@ -16357,7 +16591,7 @@
|
|
|
16357
16591
|
case 4:
|
|
16358
16592
|
// Note: [0]
|
|
16359
16593
|
if (!(_g.sent())) {
|
|
16360
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n
|
|
16594
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
16361
16595
|
}
|
|
16362
16596
|
_g.label = 5;
|
|
16363
16597
|
case 5: return [2 /*return*/, cacheFilehandler];
|
|
@@ -16532,7 +16766,7 @@
|
|
|
16532
16766
|
case 4:
|
|
16533
16767
|
files_1 = _g.sent();
|
|
16534
16768
|
if (files_1.length !== 1) {
|
|
16535
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n
|
|
16769
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
|
|
16536
16770
|
}
|
|
16537
16771
|
file = files_1[0];
|
|
16538
16772
|
return [4 /*yield*/, promises.rename(path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
|
|
@@ -16682,6 +16916,216 @@
|
|
|
16682
16916
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16683
16917
|
*/
|
|
16684
16918
|
|
|
16919
|
+
/**
|
|
16920
|
+
* Metadata of the scraper
|
|
16921
|
+
*
|
|
16922
|
+
* @private within the scraper directory
|
|
16923
|
+
*/
|
|
16924
|
+
var markitdownScraperMetadata = $deepFreeze({
|
|
16925
|
+
title: 'Markitdown scraper',
|
|
16926
|
+
packageName: '@promptbook/markitdown',
|
|
16927
|
+
className: 'MarkitdownScraper',
|
|
16928
|
+
mimeTypes: [
|
|
16929
|
+
'application/pdf',
|
|
16930
|
+
// TODO: Make priority for scrapers and than allow all mime types here:
|
|
16931
|
+
// 'text/html',
|
|
16932
|
+
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16933
|
+
],
|
|
16934
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16935
|
+
isAvilableInBrowser: false,
|
|
16936
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
16937
|
+
requiredExecutables: [],
|
|
16938
|
+
}); /* <- Note: [🤛] */
|
|
16939
|
+
/**
|
|
16940
|
+
* Registration of known scraper metadata
|
|
16941
|
+
*
|
|
16942
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
16943
|
+
*
|
|
16944
|
+
* @public exported from `@promptbook/core`
|
|
16945
|
+
* @public exported from `@promptbook/wizzard`
|
|
16946
|
+
* @public exported from `@promptbook/cli`
|
|
16947
|
+
*/
|
|
16948
|
+
var _MarkitdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markitdownScraperMetadata);
|
|
16949
|
+
/**
|
|
16950
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
16951
|
+
*/
|
|
16952
|
+
|
|
16953
|
+
/**
|
|
16954
|
+
* Integration of Markitdown by Microsoft into Promptbook
|
|
16955
|
+
*
|
|
16956
|
+
* @see https://github.com/microsoft/markitdown
|
|
16957
|
+
* @see `documentationUrl` for more details
|
|
16958
|
+
* @public exported from `@promptbook/markitdown`
|
|
16959
|
+
* @public exported from `@promptbook/pdf`
|
|
16960
|
+
*/
|
|
16961
|
+
var MarkitdownScraper = /** @class */ (function () {
|
|
16962
|
+
function MarkitdownScraper(tools, options) {
|
|
16963
|
+
this.tools = tools;
|
|
16964
|
+
this.options = options;
|
|
16965
|
+
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
16966
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16967
|
+
var MarkItDown = require('markitdown-ts').MarkItDown;
|
|
16968
|
+
// <- TODO: !!! Use Markitdown directly not through this package
|
|
16969
|
+
// <- Note: !!!!!!!
|
|
16970
|
+
this.markitdown = new MarkItDown();
|
|
16971
|
+
}
|
|
16972
|
+
Object.defineProperty(MarkitdownScraper.prototype, "metadata", {
|
|
16973
|
+
/**
|
|
16974
|
+
* Metadata of the scraper which includes title, mime types, etc.
|
|
16975
|
+
*/
|
|
16976
|
+
get: function () {
|
|
16977
|
+
return markitdownScraperMetadata;
|
|
16978
|
+
},
|
|
16979
|
+
enumerable: false,
|
|
16980
|
+
configurable: true
|
|
16981
|
+
});
|
|
16982
|
+
/**
|
|
16983
|
+
* Convert the documents to `.md` file and returns intermediate source
|
|
16984
|
+
*
|
|
16985
|
+
* Note: `$` is used to indicate that this function is not a pure function - it leaves files on the disk and you are responsible for cleaning them by calling `destroy` method of returned object
|
|
16986
|
+
*/
|
|
16987
|
+
MarkitdownScraper.prototype.$convert = function (source) {
|
|
16988
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16989
|
+
var _a, _b, rootDirname, _c, cacheDirname, _d, intermediateFilesStrategy, _e, isVerbose, cacheFilehandler, src, result;
|
|
16990
|
+
return __generator(this, function (_f) {
|
|
16991
|
+
switch (_f.label) {
|
|
16992
|
+
case 0:
|
|
16993
|
+
_a = this.options, _b = _a.rootDirname, rootDirname = _b === void 0 ? process.cwd() : _b, _c = _a.cacheDirname, cacheDirname = _c === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _c, _d = _a.intermediateFilesStrategy, intermediateFilesStrategy = _d === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _d, _e = _a.isVerbose, isVerbose = _e === void 0 ? DEFAULT_IS_VERBOSE : _e;
|
|
16994
|
+
if (!$isRunningInNode()) {
|
|
16995
|
+
throw new KnowledgeScrapeError('MarkitdownScraper is only supported in Node environment');
|
|
16996
|
+
}
|
|
16997
|
+
if (this.tools.fs === undefined) {
|
|
16998
|
+
throw new EnvironmentMismatchError('Can not scrape boilerplates without filesystem tools');
|
|
16999
|
+
// <- TODO: [🧠] What is the best error type here`
|
|
17000
|
+
}
|
|
17001
|
+
return [4 /*yield*/, getScraperIntermediateSource(source, {
|
|
17002
|
+
rootDirname: rootDirname,
|
|
17003
|
+
cacheDirname: cacheDirname,
|
|
17004
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
17005
|
+
extension: 'md',
|
|
17006
|
+
isVerbose: isVerbose,
|
|
17007
|
+
})];
|
|
17008
|
+
case 1:
|
|
17009
|
+
cacheFilehandler = _f.sent();
|
|
17010
|
+
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
17011
|
+
case 2:
|
|
17012
|
+
if (!!(_f.sent())) return [3 /*break*/, 5];
|
|
17013
|
+
src = source.filename || source.url || null;
|
|
17014
|
+
console.log('!!!', { src: src, source: source, cacheFilehandler: cacheFilehandler });
|
|
17015
|
+
if (src === null) {
|
|
17016
|
+
throw new UnexpectedError('Source has no filename or url');
|
|
17017
|
+
}
|
|
17018
|
+
return [4 /*yield*/, this.markitdown.convert(src, {
|
|
17019
|
+
// TODO: !!!!!! Pass when sacraping Youtube
|
|
17020
|
+
// enableYoutubeTranscript: true,
|
|
17021
|
+
// youtubeTranscriptLanguage: 'en',
|
|
17022
|
+
})];
|
|
17023
|
+
case 3:
|
|
17024
|
+
result = _f.sent();
|
|
17025
|
+
if (result === null || result === undefined) {
|
|
17026
|
+
throw new Error("Markitdown could not convert the \"".concat(source.source, "\""));
|
|
17027
|
+
// <- TODO: !!! Make MarkitdownError
|
|
17028
|
+
}
|
|
17029
|
+
console.log('!!!', { result: result, cacheFilehandler: cacheFilehandler });
|
|
17030
|
+
return [4 /*yield*/, this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content)];
|
|
17031
|
+
case 4:
|
|
17032
|
+
_f.sent();
|
|
17033
|
+
_f.label = 5;
|
|
17034
|
+
case 5: return [2 /*return*/, cacheFilehandler];
|
|
17035
|
+
}
|
|
17036
|
+
});
|
|
17037
|
+
});
|
|
17038
|
+
};
|
|
17039
|
+
/**
|
|
17040
|
+
* Scrapes the docx file and returns the knowledge pieces or `null` if it can't scrape it
|
|
17041
|
+
*/
|
|
17042
|
+
MarkitdownScraper.prototype.scrape = function (source) {
|
|
17043
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17044
|
+
var cacheFilehandler, markdownSource, knowledge;
|
|
17045
|
+
return __generator(this, function (_a) {
|
|
17046
|
+
switch (_a.label) {
|
|
17047
|
+
case 0: return [4 /*yield*/, this.$convert(source)];
|
|
17048
|
+
case 1:
|
|
17049
|
+
cacheFilehandler = _a.sent();
|
|
17050
|
+
markdownSource = {
|
|
17051
|
+
source: source.source,
|
|
17052
|
+
filename: cacheFilehandler.filename,
|
|
17053
|
+
url: null,
|
|
17054
|
+
mimeType: 'text/markdown',
|
|
17055
|
+
asText: function () {
|
|
17056
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
17057
|
+
return __generator(this, function (_a) {
|
|
17058
|
+
switch (_a.label) {
|
|
17059
|
+
case 0: return [4 /*yield*/, promises.readFile(cacheFilehandler.filename, 'utf-8')];
|
|
17060
|
+
case 1:
|
|
17061
|
+
// Note: [0] In $convert we check that the file exists
|
|
17062
|
+
return [2 /*return*/, _a.sent()];
|
|
17063
|
+
}
|
|
17064
|
+
});
|
|
17065
|
+
});
|
|
17066
|
+
},
|
|
17067
|
+
asJson: function () {
|
|
17068
|
+
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
17069
|
+
},
|
|
17070
|
+
/*
|
|
17071
|
+
TODO: [🥽]
|
|
17072
|
+
> asBlob() {
|
|
17073
|
+
> throw new UnexpectedError(
|
|
17074
|
+
> 'Did not expect that `markdownScraper` would need to get the content `asBlob`',
|
|
17075
|
+
> );
|
|
17076
|
+
> },
|
|
17077
|
+
*/
|
|
17078
|
+
};
|
|
17079
|
+
knowledge = this.markdownScraper.scrape(markdownSource);
|
|
17080
|
+
return [4 /*yield*/, cacheFilehandler.destroy()];
|
|
17081
|
+
case 2:
|
|
17082
|
+
_a.sent();
|
|
17083
|
+
return [2 /*return*/, knowledge];
|
|
17084
|
+
}
|
|
17085
|
+
});
|
|
17086
|
+
});
|
|
17087
|
+
};
|
|
17088
|
+
return MarkitdownScraper;
|
|
17089
|
+
}());
|
|
17090
|
+
/**
|
|
17091
|
+
* TODO: [🧠][🌜] Export only from `@promptbook/markitdown` or `@promptbook/pdf` NOT both
|
|
17092
|
+
* TODO: [👣] Converted documents can act as cached items - there is no need to run conversion each time
|
|
17093
|
+
* TODO: [🪂] Do it in parallel
|
|
17094
|
+
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
17095
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
17096
|
+
*/
|
|
17097
|
+
|
|
17098
|
+
/**
|
|
17099
|
+
* Constructor of `MarkitdownScraper`
|
|
17100
|
+
*
|
|
17101
|
+
* @public exported from `@promptbook/markitdown`
|
|
17102
|
+
* @public exported from `@promptbook/pdf`
|
|
17103
|
+
*/
|
|
17104
|
+
var createMarkitdownScraper = Object.assign(function (tools, options) {
|
|
17105
|
+
return new MarkitdownScraper(tools, options);
|
|
17106
|
+
}, markitdownScraperMetadata); /* <- Note: [🤛] */
|
|
17107
|
+
/**
|
|
17108
|
+
* TODO: [🧠][🌜] Export only from `@promptbook/markitdown` or `@promptbook/pdf` NOT both
|
|
17109
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
17110
|
+
*/
|
|
17111
|
+
|
|
17112
|
+
/**
|
|
17113
|
+
* Registration of known scraper
|
|
17114
|
+
*
|
|
17115
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
17116
|
+
*
|
|
17117
|
+
* @public exported from `@promptbook/markitdown`
|
|
17118
|
+
* @public exported from `@promptbook/pdf`
|
|
17119
|
+
* @public exported from `@promptbook/wizzard`
|
|
17120
|
+
* @public exported from `@promptbook/cli`
|
|
17121
|
+
*/
|
|
17122
|
+
var _MarkitdownScraperRegistration = $scrapersRegister.register(createMarkitdownScraper);
|
|
17123
|
+
/**
|
|
17124
|
+
* TODO: [🧠][🌜] Export only from `@promptbook/markitdown` or `@promptbook/pdf` NOT both
|
|
17125
|
+
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
17126
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
17127
|
+
*/
|
|
17128
|
+
|
|
16685
17129
|
/**
|
|
16686
17130
|
* Metadata of the scraper
|
|
16687
17131
|
*
|
|
@@ -16691,7 +17135,7 @@
|
|
|
16691
17135
|
title: 'Pdf scraper',
|
|
16692
17136
|
packageName: '@promptbook/pdf',
|
|
16693
17137
|
className: 'PdfScraper',
|
|
16694
|
-
mimeTypes: ['application/pdf'],
|
|
17138
|
+
mimeTypes: ['application/pdf-DISABLED'],
|
|
16695
17139
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
16696
17140
|
isAvilableInBrowser: false,
|
|
16697
17141
|
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
@@ -17008,6 +17452,8 @@
|
|
|
17008
17452
|
exports._AnthropicClaudeRegistration = _AnthropicClaudeRegistration;
|
|
17009
17453
|
exports._AzureOpenAiMetadataRegistration = _AzureOpenAiMetadataRegistration;
|
|
17010
17454
|
exports._AzureOpenAiRegistration = _AzureOpenAiRegistration;
|
|
17455
|
+
exports._BoilerplateScraperMetadataRegistration = _BoilerplateScraperMetadataRegistration;
|
|
17456
|
+
exports._BoilerplateScraperRegistration = _BoilerplateScraperRegistration;
|
|
17011
17457
|
exports._CLI = _CLI;
|
|
17012
17458
|
exports._DocumentScraperMetadataRegistration = _DocumentScraperMetadataRegistration;
|
|
17013
17459
|
exports._DocumentScraperRegistration = _DocumentScraperRegistration;
|
|
@@ -17017,6 +17463,8 @@
|
|
|
17017
17463
|
exports._LegacyDocumentScraperRegistration = _LegacyDocumentScraperRegistration;
|
|
17018
17464
|
exports._MarkdownScraperMetadataRegistration = _MarkdownScraperMetadataRegistration;
|
|
17019
17465
|
exports._MarkdownScraperRegistration = _MarkdownScraperRegistration;
|
|
17466
|
+
exports._MarkitdownScraperMetadataRegistration = _MarkitdownScraperMetadataRegistration;
|
|
17467
|
+
exports._MarkitdownScraperRegistration = _MarkitdownScraperRegistration;
|
|
17020
17468
|
exports._OpenAiAssistantMetadataRegistration = _OpenAiAssistantMetadataRegistration;
|
|
17021
17469
|
exports._OpenAiAssistantRegistration = _OpenAiAssistantRegistration;
|
|
17022
17470
|
exports._OpenAiMetadataRegistration = _OpenAiMetadataRegistration;
|