@promptbook/node 0.84.0-20 → 0.84.0-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -11
- package/esm/index.es.js +185 -300
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +0 -4
- package/esm/typings/src/_packages/core.index.d.ts +2 -12
- package/esm/typings/src/_packages/types.index.d.ts +0 -2
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/esm/typings/src/_packages/wizzard.index.d.ts +0 -4
- package/esm/typings/src/config.d.ts +1 -27
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -3
- package/esm/typings/src/pipeline/book-notation.d.ts +2 -3
- package/esm/typings/src/pipeline/prompt-notation.d.ts +5 -18
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -5
- package/esm/typings/src/wizzard/wizzard.d.ts +1 -7
- package/package.json +16 -9
- package/umd/index.umd.js +186 -301
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +0 -9
- package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +0 -14
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +0 -14
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +0 -15
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +0 -1
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +0 -1
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +0 -10
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +0 -1
package/esm/index.es.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink } from 'fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { join, basename, dirname } from 'path';
|
|
4
4
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
5
5
|
import { format } from 'prettier';
|
|
6
6
|
import parserHtml from 'prettier/parser-html';
|
|
7
7
|
import { forTime } from 'waitasecond';
|
|
8
8
|
import { unparse, parse } from 'papaparse';
|
|
9
|
-
import hexEncoder from 'crypto-js/enc-hex';
|
|
10
|
-
import sha256 from 'crypto-js/sha256';
|
|
11
9
|
import { SHA256 } from 'crypto-js';
|
|
12
|
-
import
|
|
10
|
+
import hexEncoder from 'crypto-js/enc-hex';
|
|
11
|
+
import { lookup } from 'mime-types';
|
|
13
12
|
import { spawn } from 'child_process';
|
|
14
13
|
import * as dotenv from 'dotenv';
|
|
14
|
+
import sha256 from 'crypto-js/sha256';
|
|
15
15
|
|
|
16
16
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
17
17
|
/**
|
|
@@ -27,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -204,18 +204,6 @@ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
|
204
204
|
* @public exported from `@promptbook/core`
|
|
205
205
|
*/
|
|
206
206
|
var DEFAULT_TASK_TITLE = "Task";
|
|
207
|
-
/**
|
|
208
|
-
* When the pipeline is flat and no name of return parameter is provided, this name is used
|
|
209
|
-
*
|
|
210
|
-
* @public exported from `@promptbook/core`
|
|
211
|
-
*/
|
|
212
|
-
var DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
|
|
213
|
-
/**
|
|
214
|
-
* Maximum file size limit
|
|
215
|
-
*
|
|
216
|
-
* @public exported from `@promptbook/core`
|
|
217
|
-
*/
|
|
218
|
-
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
219
207
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
220
208
|
/**
|
|
221
209
|
* The maximum number of iterations for a loops
|
|
@@ -274,15 +262,6 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
274
262
|
* @public exported from `@promptbook/core`
|
|
275
263
|
*/
|
|
276
264
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
277
|
-
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
278
|
-
/**
|
|
279
|
-
* Where to store the temporary downloads
|
|
280
|
-
*
|
|
281
|
-
* Note: When the folder does not exist, it is created recursively
|
|
282
|
-
*
|
|
283
|
-
* @public exported from `@promptbook/core`
|
|
284
|
-
*/
|
|
285
|
-
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
286
265
|
/**
|
|
287
266
|
* Where to store the scrape cache
|
|
288
267
|
*
|
|
@@ -338,94 +317,22 @@ true);
|
|
|
338
317
|
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"}];
|
|
339
318
|
|
|
340
319
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* @public exported from `@promptbook/utils`
|
|
344
|
-
*/
|
|
345
|
-
function isValidEmail(email) {
|
|
346
|
-
if (typeof email !== 'string') {
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
if (email.split('\n').length > 1) {
|
|
350
|
-
return false;
|
|
351
|
-
}
|
|
352
|
-
return /^.+@.+\..+$/.test(email);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Tests if given string is valid URL.
|
|
320
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
357
321
|
*
|
|
358
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
359
322
|
* @public exported from `@promptbook/utils`
|
|
360
323
|
*/
|
|
361
|
-
function
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
if (filename.split('\n').length > 1) {
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
if (filename.split(' ').length >
|
|
369
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
373
|
-
// Absolute Unix path: /hello.txt
|
|
374
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
375
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
// Absolute Windows path: /hello.txt
|
|
379
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
380
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
381
|
-
return true;
|
|
382
|
-
}
|
|
383
|
-
// Relative path: ./hello.txt
|
|
384
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
385
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
// Allow paths like foo/hello
|
|
389
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
390
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
391
|
-
return true;
|
|
392
|
-
}
|
|
393
|
-
// Allow paths like hello.book
|
|
394
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
395
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
324
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
325
|
+
try {
|
|
326
|
+
JSON.parse(value);
|
|
396
327
|
return true;
|
|
397
328
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
* TODO: [🍏] Implement for MacOs
|
|
402
|
-
*/
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Tests if given string is valid URL.
|
|
406
|
-
*
|
|
407
|
-
* Note: Dataurl are considered perfectly valid.
|
|
408
|
-
* Note: There are two simmilar functions:
|
|
409
|
-
* - `isValidUrl` which tests any URL
|
|
410
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
411
|
-
*
|
|
412
|
-
* @public exported from `@promptbook/utils`
|
|
413
|
-
*/
|
|
414
|
-
function isValidUrl(url) {
|
|
415
|
-
if (typeof url !== 'string') {
|
|
416
|
-
return false;
|
|
417
|
-
}
|
|
418
|
-
try {
|
|
419
|
-
if (url.startsWith('blob:')) {
|
|
420
|
-
url = url.replace(/^blob:/, '');
|
|
329
|
+
catch (error) {
|
|
330
|
+
if (!(error instanceof Error)) {
|
|
331
|
+
throw error;
|
|
421
332
|
}
|
|
422
|
-
|
|
423
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
333
|
+
if (error.message.includes('Unexpected token')) {
|
|
424
334
|
return false;
|
|
425
335
|
}
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
catch (error) {
|
|
429
336
|
return false;
|
|
430
337
|
}
|
|
431
338
|
}
|
|
@@ -449,27 +356,6 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
449
356
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
450
357
|
*/
|
|
451
358
|
|
|
452
|
-
/**
|
|
453
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
454
|
-
*
|
|
455
|
-
* @public exported from `@promptbook/utils`
|
|
456
|
-
*/
|
|
457
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
458
|
-
try {
|
|
459
|
-
JSON.parse(value);
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
if (!(error instanceof Error)) {
|
|
464
|
-
throw error;
|
|
465
|
-
}
|
|
466
|
-
if (error.message.includes('Unexpected token')) {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
359
|
/**
|
|
474
360
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
475
361
|
* 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.
|
|
@@ -483,15 +369,6 @@ function validatePipelineString(pipelineString) {
|
|
|
483
369
|
if (isValidJsonString(pipelineString)) {
|
|
484
370
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
485
371
|
}
|
|
486
|
-
else if (isValidUrl(pipelineString)) {
|
|
487
|
-
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
488
|
-
}
|
|
489
|
-
else if (isValidFilePath(pipelineString)) {
|
|
490
|
-
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
491
|
-
}
|
|
492
|
-
else if (isValidEmail(pipelineString)) {
|
|
493
|
-
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
494
|
-
}
|
|
495
372
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
496
373
|
return pipelineString;
|
|
497
374
|
}
|
|
@@ -1185,6 +1062,35 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
1185
1062
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1186
1063
|
}
|
|
1187
1064
|
|
|
1065
|
+
/**
|
|
1066
|
+
* Tests if given string is valid URL.
|
|
1067
|
+
*
|
|
1068
|
+
* Note: Dataurl are considered perfectly valid.
|
|
1069
|
+
* Note: There are two simmilar functions:
|
|
1070
|
+
* - `isValidUrl` which tests any URL
|
|
1071
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1072
|
+
*
|
|
1073
|
+
* @public exported from `@promptbook/utils`
|
|
1074
|
+
*/
|
|
1075
|
+
function isValidUrl(url) {
|
|
1076
|
+
if (typeof url !== 'string') {
|
|
1077
|
+
return false;
|
|
1078
|
+
}
|
|
1079
|
+
try {
|
|
1080
|
+
if (url.startsWith('blob:')) {
|
|
1081
|
+
url = url.replace(/^blob:/, '');
|
|
1082
|
+
}
|
|
1083
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
1084
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
catch (error) {
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1188
1094
|
/**
|
|
1189
1095
|
* Tests if given string is valid pipeline URL URL.
|
|
1190
1096
|
*
|
|
@@ -1939,28 +1845,12 @@ function deserializeError(error) {
|
|
|
1939
1845
|
/**
|
|
1940
1846
|
* Asserts that the execution of a Promptbook is successful
|
|
1941
1847
|
*
|
|
1942
|
-
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
1943
|
-
*
|
|
1944
1848
|
* @param executionResult - The partial result of the Promptbook execution
|
|
1945
1849
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1946
1850
|
* @public exported from `@promptbook/core`
|
|
1947
1851
|
*/
|
|
1948
1852
|
function assertsExecutionSuccessful(executionResult) {
|
|
1949
|
-
var
|
|
1950
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
1951
|
-
try {
|
|
1952
|
-
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
1953
|
-
var warning = warnings_1_1.value;
|
|
1954
|
-
console.warn(warning.message);
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1958
|
-
finally {
|
|
1959
|
-
try {
|
|
1960
|
-
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
1961
|
-
}
|
|
1962
|
-
finally { if (e_1) throw e_1.error; }
|
|
1963
|
-
}
|
|
1853
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
1964
1854
|
if (isSuccessful === true) {
|
|
1965
1855
|
return;
|
|
1966
1856
|
}
|
|
@@ -5417,15 +5307,6 @@ function knowledgeSourceContentToName(knowledgeSourceContent) {
|
|
|
5417
5307
|
* TODO: [🐱🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
|
|
5418
5308
|
*/
|
|
5419
5309
|
|
|
5420
|
-
/**
|
|
5421
|
-
* @@@
|
|
5422
|
-
*
|
|
5423
|
-
* @private for `FileCacheStorage`
|
|
5424
|
-
*/
|
|
5425
|
-
function nameToSubfolderPath(name) {
|
|
5426
|
-
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
5427
|
-
}
|
|
5428
|
-
|
|
5429
5310
|
/**
|
|
5430
5311
|
* Convert file extension to mime type
|
|
5431
5312
|
*
|
|
@@ -5482,55 +5363,53 @@ function isFileExisting(filename, fs) {
|
|
|
5482
5363
|
*/
|
|
5483
5364
|
|
|
5484
5365
|
/**
|
|
5485
|
-
*
|
|
5486
|
-
*
|
|
5487
|
-
* Note: If the mime type is invalid, `null` is returned
|
|
5488
|
-
*
|
|
5489
|
-
* @private within the repository
|
|
5490
|
-
*/
|
|
5491
|
-
function mimeTypeToExtension(value) {
|
|
5492
|
-
return extension(value) || null;
|
|
5493
|
-
}
|
|
5494
|
-
|
|
5495
|
-
/**
|
|
5496
|
-
* Removes emojis from a string and fix whitespaces
|
|
5497
|
-
*
|
|
5498
|
-
* @param text with emojis
|
|
5499
|
-
* @returns text without emojis
|
|
5500
|
-
* @public exported from `@promptbook/utils`
|
|
5501
|
-
*/
|
|
5502
|
-
function removeEmojis(text) {
|
|
5503
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
5504
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
5505
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
5506
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
5507
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
5508
|
-
return text;
|
|
5509
|
-
}
|
|
5510
|
-
|
|
5511
|
-
/**
|
|
5512
|
-
* @@@
|
|
5366
|
+
* Tests if given string is valid URL.
|
|
5513
5367
|
*
|
|
5514
|
-
*
|
|
5515
|
-
* @returns @@@
|
|
5516
|
-
* @example @@@
|
|
5368
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
5517
5369
|
* @public exported from `@promptbook/utils`
|
|
5518
5370
|
*/
|
|
5519
|
-
function
|
|
5520
|
-
if (
|
|
5521
|
-
|
|
5522
|
-
value = value.replace(/\.html$/, '');
|
|
5371
|
+
function isValidFilePath(filename) {
|
|
5372
|
+
if (typeof filename !== 'string') {
|
|
5373
|
+
return false;
|
|
5523
5374
|
}
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
// Note: Keeping extension in the name
|
|
5375
|
+
if (filename.split('\n').length > 1) {
|
|
5376
|
+
return false;
|
|
5527
5377
|
}
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5378
|
+
if (filename.split(' ').length >
|
|
5379
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
5380
|
+
return false;
|
|
5381
|
+
}
|
|
5382
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
5383
|
+
// Absolute Unix path: /hello.txt
|
|
5384
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
5385
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
5386
|
+
return true;
|
|
5387
|
+
}
|
|
5388
|
+
// Absolute Windows path: /hello.txt
|
|
5389
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
5390
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
5391
|
+
return true;
|
|
5392
|
+
}
|
|
5393
|
+
// Relative path: ./hello.txt
|
|
5394
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
5395
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
5396
|
+
return true;
|
|
5397
|
+
}
|
|
5398
|
+
// Allow paths like foo/hello
|
|
5399
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
5400
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
5401
|
+
return true;
|
|
5402
|
+
}
|
|
5403
|
+
// Allow paths like hello.book
|
|
5404
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
5405
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
5406
|
+
return true;
|
|
5407
|
+
}
|
|
5408
|
+
return false;
|
|
5533
5409
|
}
|
|
5410
|
+
/**
|
|
5411
|
+
* TODO: [🍏] Implement for MacOs
|
|
5412
|
+
*/
|
|
5534
5413
|
|
|
5535
5414
|
/**
|
|
5536
5415
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
@@ -5567,9 +5446,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
5567
5446
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5568
5447
|
var _a;
|
|
5569
5448
|
return __awaiter(this, void 0, void 0, function () {
|
|
5570
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType,
|
|
5571
|
-
return __generator(this, function (
|
|
5572
|
-
switch (
|
|
5449
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
5450
|
+
return __generator(this, function (_f) {
|
|
5451
|
+
switch (_f.label) {
|
|
5573
5452
|
case 0:
|
|
5574
5453
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
5575
5454
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
@@ -5578,76 +5457,54 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5578
5457
|
if (!name) {
|
|
5579
5458
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
5580
5459
|
}
|
|
5581
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
5460
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
|
|
5582
5461
|
url = knowledgeSourceContent;
|
|
5583
5462
|
return [4 /*yield*/, fetch(url)];
|
|
5584
5463
|
case 1:
|
|
5585
|
-
response_1 =
|
|
5464
|
+
response_1 = _f.sent();
|
|
5586
5465
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
}
|
|
5611
|
-
});
|
|
5466
|
+
return [2 /*return*/, {
|
|
5467
|
+
source: name,
|
|
5468
|
+
filename: null,
|
|
5469
|
+
url: url,
|
|
5470
|
+
mimeType: mimeType,
|
|
5471
|
+
/*
|
|
5472
|
+
TODO: [🥽]
|
|
5473
|
+
> async asBlob() {
|
|
5474
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
5475
|
+
> const content = await response.blob();
|
|
5476
|
+
> return content;
|
|
5477
|
+
> },
|
|
5478
|
+
*/
|
|
5479
|
+
asJson: function () {
|
|
5480
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5481
|
+
var content;
|
|
5482
|
+
return __generator(this, function (_a) {
|
|
5483
|
+
switch (_a.label) {
|
|
5484
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
5485
|
+
case 1:
|
|
5486
|
+
content = _a.sent();
|
|
5487
|
+
return [2 /*return*/, content];
|
|
5488
|
+
}
|
|
5612
5489
|
});
|
|
5613
|
-
}
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
}
|
|
5490
|
+
});
|
|
5491
|
+
},
|
|
5492
|
+
asText: function () {
|
|
5493
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5494
|
+
var content;
|
|
5495
|
+
return __generator(this, function (_a) {
|
|
5496
|
+
switch (_a.label) {
|
|
5497
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
5498
|
+
case 1:
|
|
5499
|
+
content = _a.sent();
|
|
5500
|
+
return [2 /*return*/, content];
|
|
5501
|
+
}
|
|
5625
5502
|
});
|
|
5626
|
-
}
|
|
5627
|
-
}
|
|
5628
|
-
|
|
5629
|
-
basename = url.split('/').pop() || titleToName(url);
|
|
5630
|
-
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
5631
|
-
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
5632
|
-
filepath = 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));
|
|
5633
|
-
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
5503
|
+
});
|
|
5504
|
+
},
|
|
5505
|
+
}];
|
|
5634
5506
|
case 2:
|
|
5635
|
-
|
|
5636
|
-
_g = (_f = Buffer).from;
|
|
5637
|
-
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
5638
|
-
case 3:
|
|
5639
|
-
fileContent = _g.apply(_f, [_h.sent()]);
|
|
5640
|
-
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
5641
|
-
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."));
|
|
5642
|
-
}
|
|
5643
|
-
return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
|
|
5644
|
-
case 4:
|
|
5645
|
-
_h.sent();
|
|
5646
|
-
// TODO: [💵] Check the file security
|
|
5647
|
-
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
5648
|
-
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
5649
|
-
case 5:
|
|
5650
|
-
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
5507
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
|
|
5651
5508
|
if (tools.fs === undefined) {
|
|
5652
5509
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
5653
5510
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -5660,8 +5517,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5660
5517
|
fileExtension = getFileExtension(filename_1);
|
|
5661
5518
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
5662
5519
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5663
|
-
case
|
|
5664
|
-
if (!(
|
|
5520
|
+
case 3:
|
|
5521
|
+
if (!(_f.sent())) {
|
|
5665
5522
|
throw new NotFoundError(spaceTrim(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 "); }));
|
|
5666
5523
|
}
|
|
5667
5524
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -5707,7 +5564,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5707
5564
|
});
|
|
5708
5565
|
},
|
|
5709
5566
|
}];
|
|
5710
|
-
case
|
|
5567
|
+
case 4: return [2 /*return*/, {
|
|
5711
5568
|
source: name,
|
|
5712
5569
|
filename: null,
|
|
5713
5570
|
url: null,
|
|
@@ -6818,6 +6675,22 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
|
6818
6675
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
6819
6676
|
*/
|
|
6820
6677
|
|
|
6678
|
+
/**
|
|
6679
|
+
* Removes emojis from a string and fix whitespaces
|
|
6680
|
+
*
|
|
6681
|
+
* @param text with emojis
|
|
6682
|
+
* @returns text without emojis
|
|
6683
|
+
* @public exported from `@promptbook/utils`
|
|
6684
|
+
*/
|
|
6685
|
+
function removeEmojis(text) {
|
|
6686
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
6687
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
6688
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
6689
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
6690
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
6691
|
+
return text;
|
|
6692
|
+
}
|
|
6693
|
+
|
|
6821
6694
|
/**
|
|
6822
6695
|
* Removes quotes from a string
|
|
6823
6696
|
*
|
|
@@ -8765,15 +8638,12 @@ function isFlatPipeline(pipelineString) {
|
|
|
8765
8638
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
8766
8639
|
pipelineString = spaceTrim(pipelineString);
|
|
8767
8640
|
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
|
|
8771
|
-
var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
|
|
8772
|
-
// TODO: [🧉] Also (double)check
|
|
8641
|
+
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
8642
|
+
// TODO: Also (double)check
|
|
8773
8643
|
// > const usedCommands
|
|
8774
8644
|
// > const isBlocksUsed
|
|
8775
8645
|
// > const returnStatementCount
|
|
8776
|
-
var isFlat = !isMarkdownBeginningWithHeadline &&
|
|
8646
|
+
var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
8777
8647
|
return isFlat;
|
|
8778
8648
|
}
|
|
8779
8649
|
|
|
@@ -8787,26 +8657,9 @@ function deflatePipeline(pipelineString) {
|
|
|
8787
8657
|
return pipelineString;
|
|
8788
8658
|
}
|
|
8789
8659
|
var pipelineStringLines = pipelineString.split('\n');
|
|
8790
|
-
var
|
|
8791
|
-
var returnStatement;
|
|
8792
|
-
if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
|
|
8793
|
-
// Note: Last line is return statement
|
|
8794
|
-
returnStatement = potentialReturnStatement;
|
|
8795
|
-
}
|
|
8796
|
-
else {
|
|
8797
|
-
// Note: Last line is not a return statement
|
|
8798
|
-
returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
|
|
8799
|
-
pipelineStringLines.push(potentialReturnStatement);
|
|
8800
|
-
}
|
|
8660
|
+
var returnStatement = pipelineStringLines.pop();
|
|
8801
8661
|
var prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
8802
|
-
|
|
8803
|
-
if (prompt.split('\n').length <= 1) {
|
|
8804
|
-
quotedPrompt = "> ".concat(prompt);
|
|
8805
|
-
}
|
|
8806
|
-
else {
|
|
8807
|
-
quotedPrompt = spaceTrim(function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
|
|
8808
|
-
}
|
|
8809
|
-
pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ").concat(block(quotedPrompt), "\n\n ").concat(returnStatement, "\n "); }));
|
|
8662
|
+
pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
|
|
8810
8663
|
// <- TODO: Maybe use book` notation
|
|
8811
8664
|
return pipelineString;
|
|
8812
8665
|
}
|
|
@@ -9029,6 +8882,30 @@ function flattenMarkdown(markdown) {
|
|
|
9029
8882
|
* NOW we are working just with markdown string and its good enough
|
|
9030
8883
|
*/
|
|
9031
8884
|
|
|
8885
|
+
/**
|
|
8886
|
+
* @@@
|
|
8887
|
+
*
|
|
8888
|
+
* @param value @@@
|
|
8889
|
+
* @returns @@@
|
|
8890
|
+
* @example @@@
|
|
8891
|
+
* @public exported from `@promptbook/utils`
|
|
8892
|
+
*/
|
|
8893
|
+
function titleToName(value) {
|
|
8894
|
+
if (isValidUrl(value)) {
|
|
8895
|
+
value = value.replace(/^https?:\/\//, '');
|
|
8896
|
+
value = value.replace(/\.html$/, '');
|
|
8897
|
+
}
|
|
8898
|
+
else if (isValidFilePath(value)) {
|
|
8899
|
+
value = basename(value);
|
|
8900
|
+
// Note: Keeping extension in the name
|
|
8901
|
+
}
|
|
8902
|
+
value = value.split('/').join('-');
|
|
8903
|
+
value = removeEmojis(value);
|
|
8904
|
+
value = normalizeToKebabCase(value);
|
|
8905
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
8906
|
+
return value;
|
|
8907
|
+
}
|
|
8908
|
+
|
|
9032
8909
|
/**
|
|
9033
8910
|
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
9034
8911
|
*
|
|
@@ -9761,7 +9638,6 @@ function $provideFilesystemForNode(options) {
|
|
|
9761
9638
|
readFile: readFile,
|
|
9762
9639
|
writeFile: writeFile,
|
|
9763
9640
|
readdir: readdir,
|
|
9764
|
-
mkdir: mkdir,
|
|
9765
9641
|
};
|
|
9766
9642
|
}
|
|
9767
9643
|
/**
|
|
@@ -11380,6 +11256,15 @@ function stringifyPipelineJson(pipeline) {
|
|
|
11380
11256
|
* TODO: [🍙] Make some standard order of json properties
|
|
11381
11257
|
*/
|
|
11382
11258
|
|
|
11259
|
+
/**
|
|
11260
|
+
* @@@
|
|
11261
|
+
*
|
|
11262
|
+
* @private for `FileCacheStorage`
|
|
11263
|
+
*/
|
|
11264
|
+
function nameToSubfolderPath(name) {
|
|
11265
|
+
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
11266
|
+
}
|
|
11267
|
+
|
|
11383
11268
|
/**
|
|
11384
11269
|
* @@@
|
|
11385
11270
|
*
|