@promptbook/markdown-utils 0.84.0-9 → 0.84.0
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 +21 -9
- package/esm/index.es.js +271 -164
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +12 -2
- package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/about.d.ts +4 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +3 -1
- package/esm/typings/src/config.d.ts +27 -1
- 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 +3 -1
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +9 -0
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +9 -0
- package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +14 -0
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +14 -0
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +15 -0
- package/esm/typings/src/pipeline/book-notation.d.ts +3 -2
- package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -5
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +5 -2
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +3 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +7 -1
- package/package.json +7 -14
- package/umd/index.umd.js +272 -165
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, path, cryptoJs,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, hexEncoder, sha256, path, cryptoJs, 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 parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
11
11
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
12
|
+
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
12
13
|
|
|
13
14
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
14
15
|
/**
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
* @generated
|
|
25
26
|
* @see https://github.com/webgptorg/promptbook
|
|
26
27
|
*/
|
|
27
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
|
|
28
29
|
/**
|
|
29
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -362,6 +363,99 @@
|
|
|
362
363
|
|
|
363
364
|
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"}];
|
|
364
365
|
|
|
366
|
+
/**
|
|
367
|
+
* Checks if value is valid email
|
|
368
|
+
*
|
|
369
|
+
* @public exported from `@promptbook/utils`
|
|
370
|
+
*/
|
|
371
|
+
function isValidEmail(email) {
|
|
372
|
+
if (typeof email !== 'string') {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
if (email.split('\n').length > 1) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
return /^.+@.+\..+$/.test(email);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Tests if given string is valid URL.
|
|
383
|
+
*
|
|
384
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
385
|
+
* @public exported from `@promptbook/utils`
|
|
386
|
+
*/
|
|
387
|
+
function isValidFilePath(filename) {
|
|
388
|
+
if (typeof filename !== 'string') {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (filename.split('\n').length > 1) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
if (filename.split(' ').length >
|
|
395
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
399
|
+
// Absolute Unix path: /hello.txt
|
|
400
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
401
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
// Absolute Windows path: /hello.txt
|
|
405
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
406
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
// Relative path: ./hello.txt
|
|
410
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
411
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
// Allow paths like foo/hello
|
|
415
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
416
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
// Allow paths like hello.book
|
|
420
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
421
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* TODO: [🍏] Implement for MacOs
|
|
428
|
+
*/
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Tests if given string is valid URL.
|
|
432
|
+
*
|
|
433
|
+
* Note: Dataurl are considered perfectly valid.
|
|
434
|
+
* Note: There are two simmilar functions:
|
|
435
|
+
* - `isValidUrl` which tests any URL
|
|
436
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
437
|
+
*
|
|
438
|
+
* @public exported from `@promptbook/utils`
|
|
439
|
+
*/
|
|
440
|
+
function isValidUrl(url) {
|
|
441
|
+
if (typeof url !== 'string') {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
try {
|
|
445
|
+
if (url.startsWith('blob:')) {
|
|
446
|
+
url = url.replace(/^blob:/, '');
|
|
447
|
+
}
|
|
448
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
449
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
365
459
|
/**
|
|
366
460
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
367
461
|
* 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.
|
|
@@ -375,6 +469,15 @@
|
|
|
375
469
|
if (isValidJsonString(pipelineString)) {
|
|
376
470
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
377
471
|
}
|
|
472
|
+
else if (isValidUrl(pipelineString)) {
|
|
473
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
474
|
+
}
|
|
475
|
+
else if (isValidFilePath(pipelineString)) {
|
|
476
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
477
|
+
}
|
|
478
|
+
else if (isValidEmail(pipelineString)) {
|
|
479
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
480
|
+
}
|
|
378
481
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
379
482
|
return pipelineString;
|
|
380
483
|
}
|
|
@@ -675,6 +778,12 @@
|
|
|
675
778
|
* @public exported from `@promptbook/core`
|
|
676
779
|
*/
|
|
677
780
|
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
781
|
+
/**
|
|
782
|
+
* Maximum file size limit
|
|
783
|
+
*
|
|
784
|
+
* @public exported from `@promptbook/core`
|
|
785
|
+
*/
|
|
786
|
+
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
678
787
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
679
788
|
/**
|
|
680
789
|
* The maximum number of iterations for a loops
|
|
@@ -708,6 +817,12 @@
|
|
|
708
817
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
709
818
|
*/
|
|
710
819
|
var IMMEDIATE_TIME = 10;
|
|
820
|
+
/**
|
|
821
|
+
* The maximum length of the (generated) filename
|
|
822
|
+
*
|
|
823
|
+
* @public exported from `@promptbook/core`
|
|
824
|
+
*/
|
|
825
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
711
826
|
/**
|
|
712
827
|
* Strategy for caching the intermediate results for knowledge sources
|
|
713
828
|
*
|
|
@@ -727,6 +842,15 @@
|
|
|
727
842
|
* @public exported from `@promptbook/core`
|
|
728
843
|
*/
|
|
729
844
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
845
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
846
|
+
/**
|
|
847
|
+
* Where to store the temporary downloads
|
|
848
|
+
*
|
|
849
|
+
* Note: When the folder does not exist, it is created recursively
|
|
850
|
+
*
|
|
851
|
+
* @public exported from `@promptbook/core`
|
|
852
|
+
*/
|
|
853
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
730
854
|
/**
|
|
731
855
|
* Where to store the scrape cache
|
|
732
856
|
*
|
|
@@ -1209,35 +1333,6 @@
|
|
|
1209
1333
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1210
1334
|
}
|
|
1211
1335
|
|
|
1212
|
-
/**
|
|
1213
|
-
* Tests if given string is valid URL.
|
|
1214
|
-
*
|
|
1215
|
-
* Note: Dataurl are considered perfectly valid.
|
|
1216
|
-
* Note: There are two simmilar functions:
|
|
1217
|
-
* - `isValidUrl` which tests any URL
|
|
1218
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1219
|
-
*
|
|
1220
|
-
* @public exported from `@promptbook/utils`
|
|
1221
|
-
*/
|
|
1222
|
-
function isValidUrl(url) {
|
|
1223
|
-
if (typeof url !== 'string') {
|
|
1224
|
-
return false;
|
|
1225
|
-
}
|
|
1226
|
-
try {
|
|
1227
|
-
if (url.startsWith('blob:')) {
|
|
1228
|
-
url = url.replace(/^blob:/, '');
|
|
1229
|
-
}
|
|
1230
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
1231
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1232
|
-
return false;
|
|
1233
|
-
}
|
|
1234
|
-
return true;
|
|
1235
|
-
}
|
|
1236
|
-
catch (error) {
|
|
1237
|
-
return false;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
1336
|
/**
|
|
1242
1337
|
* Tests if given string is valid pipeline URL URL.
|
|
1243
1338
|
*
|
|
@@ -1992,12 +2087,28 @@
|
|
|
1992
2087
|
/**
|
|
1993
2088
|
* Asserts that the execution of a Promptbook is successful
|
|
1994
2089
|
*
|
|
2090
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2091
|
+
*
|
|
1995
2092
|
* @param executionResult - The partial result of the Promptbook execution
|
|
1996
2093
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1997
2094
|
* @public exported from `@promptbook/core`
|
|
1998
2095
|
*/
|
|
1999
2096
|
function assertsExecutionSuccessful(executionResult) {
|
|
2000
|
-
var
|
|
2097
|
+
var e_1, _a;
|
|
2098
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2099
|
+
try {
|
|
2100
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2101
|
+
var warning = warnings_1_1.value;
|
|
2102
|
+
console.warn(warning.message);
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2106
|
+
finally {
|
|
2107
|
+
try {
|
|
2108
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2109
|
+
}
|
|
2110
|
+
finally { if (e_1) throw e_1.error; }
|
|
2111
|
+
}
|
|
2001
2112
|
if (isSuccessful === true) {
|
|
2002
2113
|
return;
|
|
2003
2114
|
}
|
|
@@ -2634,7 +2745,7 @@
|
|
|
2634
2745
|
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
2635
2746
|
throw error_1;
|
|
2636
2747
|
}
|
|
2637
|
-
errors.push(error_1);
|
|
2748
|
+
errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
|
|
2638
2749
|
return [3 /*break*/, 13];
|
|
2639
2750
|
case 13:
|
|
2640
2751
|
_b = _a.next();
|
|
@@ -2661,7 +2772,10 @@
|
|
|
2661
2772
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
2662
2773
|
// 3) ...
|
|
2663
2774
|
spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2664
|
-
.map(function (
|
|
2775
|
+
.map(function (_a, i) {
|
|
2776
|
+
var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
|
|
2777
|
+
return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
|
|
2778
|
+
})
|
|
2665
2779
|
.join('\n')), "\n\n "); }));
|
|
2666
2780
|
}
|
|
2667
2781
|
else if (this.llmExecutionTools.length === 0) {
|
|
@@ -3447,6 +3561,15 @@
|
|
|
3447
3561
|
* TODO: [🐱🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
|
|
3448
3562
|
*/
|
|
3449
3563
|
|
|
3564
|
+
/**
|
|
3565
|
+
* @@@
|
|
3566
|
+
*
|
|
3567
|
+
* @private for `FileCacheStorage`
|
|
3568
|
+
*/
|
|
3569
|
+
function nameToSubfolderPath(name) {
|
|
3570
|
+
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3450
3573
|
/**
|
|
3451
3574
|
* Convert file extension to mime type
|
|
3452
3575
|
*
|
|
@@ -3503,53 +3626,55 @@
|
|
|
3503
3626
|
*/
|
|
3504
3627
|
|
|
3505
3628
|
/**
|
|
3506
|
-
*
|
|
3629
|
+
* Convert mime type to file extension
|
|
3507
3630
|
*
|
|
3508
|
-
* Note:
|
|
3631
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
3632
|
+
*
|
|
3633
|
+
* @private within the repository
|
|
3634
|
+
*/
|
|
3635
|
+
function mimeTypeToExtension(value) {
|
|
3636
|
+
return mimeTypes.extension(value) || null;
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
/**
|
|
3640
|
+
* Removes emojis from a string and fix whitespaces
|
|
3641
|
+
*
|
|
3642
|
+
* @param text with emojis
|
|
3643
|
+
* @returns text without emojis
|
|
3509
3644
|
* @public exported from `@promptbook/utils`
|
|
3510
3645
|
*/
|
|
3511
|
-
function
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
}
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
if (filename.split(' ').length >
|
|
3519
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
3520
|
-
return false;
|
|
3521
|
-
}
|
|
3522
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
3523
|
-
// Absolute Unix path: /hello.txt
|
|
3524
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
3525
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
3526
|
-
return true;
|
|
3527
|
-
}
|
|
3528
|
-
// Absolute Windows path: /hello.txt
|
|
3529
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
3530
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
3531
|
-
return true;
|
|
3532
|
-
}
|
|
3533
|
-
// Relative path: ./hello.txt
|
|
3534
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
3535
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
3536
|
-
return true;
|
|
3537
|
-
}
|
|
3538
|
-
// Allow paths like foo/hello
|
|
3539
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
3540
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
3541
|
-
return true;
|
|
3542
|
-
}
|
|
3543
|
-
// Allow paths like hello.book
|
|
3544
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
3545
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
3546
|
-
return true;
|
|
3547
|
-
}
|
|
3548
|
-
return false;
|
|
3646
|
+
function removeEmojis(text) {
|
|
3647
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
3648
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
3649
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
3650
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
3651
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
3652
|
+
return text;
|
|
3549
3653
|
}
|
|
3654
|
+
|
|
3550
3655
|
/**
|
|
3551
|
-
*
|
|
3656
|
+
* @@@
|
|
3657
|
+
*
|
|
3658
|
+
* @param value @@@
|
|
3659
|
+
* @returns @@@
|
|
3660
|
+
* @example @@@
|
|
3661
|
+
* @public exported from `@promptbook/utils`
|
|
3552
3662
|
*/
|
|
3663
|
+
function titleToName(value) {
|
|
3664
|
+
if (isValidUrl(value)) {
|
|
3665
|
+
value = value.replace(/^https?:\/\//, '');
|
|
3666
|
+
value = value.replace(/\.html$/, '');
|
|
3667
|
+
}
|
|
3668
|
+
else if (isValidFilePath(value)) {
|
|
3669
|
+
value = path.basename(value);
|
|
3670
|
+
// Note: Keeping extension in the name
|
|
3671
|
+
}
|
|
3672
|
+
value = value.split('/').join('-');
|
|
3673
|
+
value = removeEmojis(value);
|
|
3674
|
+
value = normalizeToKebabCase(value);
|
|
3675
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
3676
|
+
return value;
|
|
3677
|
+
}
|
|
3553
3678
|
|
|
3554
3679
|
/**
|
|
3555
3680
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
@@ -3586,9 +3711,9 @@
|
|
|
3586
3711
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3587
3712
|
var _a;
|
|
3588
3713
|
return __awaiter(this, void 0, void 0, function () {
|
|
3589
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3590
|
-
return __generator(this, function (
|
|
3591
|
-
switch (
|
|
3714
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
|
|
3715
|
+
return __generator(this, function (_h) {
|
|
3716
|
+
switch (_h.label) {
|
|
3592
3717
|
case 0:
|
|
3593
3718
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3594
3719
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -3597,54 +3722,76 @@
|
|
|
3597
3722
|
if (!name) {
|
|
3598
3723
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3599
3724
|
}
|
|
3600
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3725
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3601
3726
|
url = knowledgeSourceContent;
|
|
3602
3727
|
return [4 /*yield*/, fetch(url)];
|
|
3603
3728
|
case 1:
|
|
3604
|
-
response_1 =
|
|
3729
|
+
response_1 = _h.sent();
|
|
3605
3730
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3731
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
3732
|
+
return [2 /*return*/, {
|
|
3733
|
+
source: name,
|
|
3734
|
+
filename: null,
|
|
3735
|
+
url: url,
|
|
3736
|
+
mimeType: mimeType,
|
|
3737
|
+
/*
|
|
3738
|
+
TODO: [🥽]
|
|
3739
|
+
> async asBlob() {
|
|
3740
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3741
|
+
> const content = await response.blob();
|
|
3742
|
+
> return content;
|
|
3743
|
+
> },
|
|
3744
|
+
*/
|
|
3745
|
+
asJson: function () {
|
|
3746
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3747
|
+
var content;
|
|
3748
|
+
return __generator(this, function (_a) {
|
|
3749
|
+
switch (_a.label) {
|
|
3750
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3751
|
+
case 1:
|
|
3752
|
+
content = _a.sent();
|
|
3753
|
+
return [2 /*return*/, content];
|
|
3754
|
+
}
|
|
3755
|
+
});
|
|
3629
3756
|
});
|
|
3630
|
-
}
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
}
|
|
3757
|
+
},
|
|
3758
|
+
asText: function () {
|
|
3759
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3760
|
+
var content;
|
|
3761
|
+
return __generator(this, function (_a) {
|
|
3762
|
+
switch (_a.label) {
|
|
3763
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3764
|
+
case 1:
|
|
3765
|
+
content = _a.sent();
|
|
3766
|
+
return [2 /*return*/, content];
|
|
3767
|
+
}
|
|
3768
|
+
});
|
|
3642
3769
|
});
|
|
3643
|
-
}
|
|
3644
|
-
}
|
|
3645
|
-
|
|
3770
|
+
},
|
|
3771
|
+
}];
|
|
3772
|
+
}
|
|
3773
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3774
|
+
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3775
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3776
|
+
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));
|
|
3777
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3646
3778
|
case 2:
|
|
3647
|
-
|
|
3779
|
+
_h.sent();
|
|
3780
|
+
_g = (_f = Buffer).from;
|
|
3781
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3782
|
+
case 3:
|
|
3783
|
+
fileContent = _g.apply(_f, [_h.sent()]);
|
|
3784
|
+
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3785
|
+
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."));
|
|
3786
|
+
}
|
|
3787
|
+
return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
|
|
3788
|
+
case 4:
|
|
3789
|
+
_h.sent();
|
|
3790
|
+
// TODO: [💵] Check the file security
|
|
3791
|
+
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3792
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3793
|
+
case 5:
|
|
3794
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3648
3795
|
if (tools.fs === undefined) {
|
|
3649
3796
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3650
3797
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -3657,8 +3804,8 @@
|
|
|
3657
3804
|
fileExtension = getFileExtension(filename_1);
|
|
3658
3805
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3659
3806
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3660
|
-
case
|
|
3661
|
-
if (!(
|
|
3807
|
+
case 6:
|
|
3808
|
+
if (!(_h.sent())) {
|
|
3662
3809
|
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 "); }));
|
|
3663
3810
|
}
|
|
3664
3811
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3704,7 +3851,7 @@
|
|
|
3704
3851
|
});
|
|
3705
3852
|
},
|
|
3706
3853
|
}];
|
|
3707
|
-
case
|
|
3854
|
+
case 7: return [2 /*return*/, {
|
|
3708
3855
|
source: name,
|
|
3709
3856
|
filename: null,
|
|
3710
3857
|
url: null,
|
|
@@ -5934,46 +6081,6 @@
|
|
|
5934
6081
|
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5935
6082
|
*/
|
|
5936
6083
|
|
|
5937
|
-
/**
|
|
5938
|
-
* Removes emojis from a string and fix whitespaces
|
|
5939
|
-
*
|
|
5940
|
-
* @param text with emojis
|
|
5941
|
-
* @returns text without emojis
|
|
5942
|
-
* @public exported from `@promptbook/utils`
|
|
5943
|
-
*/
|
|
5944
|
-
function removeEmojis(text) {
|
|
5945
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
5946
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
5947
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
5948
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
5949
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
5950
|
-
return text;
|
|
5951
|
-
}
|
|
5952
|
-
|
|
5953
|
-
/**
|
|
5954
|
-
* @@@
|
|
5955
|
-
*
|
|
5956
|
-
* @param value @@@
|
|
5957
|
-
* @returns @@@
|
|
5958
|
-
* @example @@@
|
|
5959
|
-
* @public exported from `@promptbook/utils`
|
|
5960
|
-
*/
|
|
5961
|
-
function titleToName(value) {
|
|
5962
|
-
if (isValidUrl(value)) {
|
|
5963
|
-
value = value.replace(/^https?:\/\//, '');
|
|
5964
|
-
value = value.replace(/\.html$/, '');
|
|
5965
|
-
}
|
|
5966
|
-
else if (isValidFilePath(value)) {
|
|
5967
|
-
value = path.basename(value);
|
|
5968
|
-
// Note: Keeping extension in the name
|
|
5969
|
-
}
|
|
5970
|
-
value = value.split('/').join('-');
|
|
5971
|
-
value = removeEmojis(value);
|
|
5972
|
-
value = normalizeToKebabCase(value);
|
|
5973
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
5974
|
-
return value;
|
|
5975
|
-
}
|
|
5976
|
-
|
|
5977
6084
|
/**
|
|
5978
6085
|
* Metadata of the scraper
|
|
5979
6086
|
*
|