@promptbook/markdown-utils 0.89.0-3 → 0.89.0-30
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 +9 -7
- package/esm/index.es.js +615 -532
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +40 -0
- package/esm/typings/src/_packages/core.index.d.ts +20 -8
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +24 -12
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +28 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +24 -26
- package/esm/typings/src/errors/0-index.d.ts +9 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +11 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +45 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
- package/esm/typings/src/remote-server/openapi.d.ts +187 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -4
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +84 -9
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +19 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +7 -3
- package/umd/index.umd.js +615 -532
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
- package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-30';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -173,546 +173,663 @@
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
|
-
*
|
|
176
|
+
* Returns the same value that is passed as argument.
|
|
177
|
+
* No side effects.
|
|
177
178
|
*
|
|
178
|
-
*
|
|
179
|
+
* Note: It can be usefull for:
|
|
180
|
+
*
|
|
181
|
+
* 1) Leveling indentation
|
|
182
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
183
|
+
*
|
|
184
|
+
* @param value any values
|
|
185
|
+
* @returns the same values
|
|
186
|
+
* @private within the repository
|
|
179
187
|
*/
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
if (!(error instanceof Error)) {
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
if (error.message.includes('Unexpected token')) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
return false;
|
|
188
|
+
function just(value) {
|
|
189
|
+
if (value === undefined) {
|
|
190
|
+
return undefined;
|
|
193
191
|
}
|
|
192
|
+
return value;
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
/**
|
|
197
|
-
*
|
|
196
|
+
* Warning message for the generated sections and files files
|
|
198
197
|
*
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
* @private within the repository
|
|
199
|
+
*/
|
|
200
|
+
const GENERATOR_WARNING = `⚠️ WARNING: This code has been generated so that any manual changes will be overwritten`;
|
|
201
|
+
/**
|
|
202
|
+
* Name for the Promptbook
|
|
202
203
|
*
|
|
203
|
-
*
|
|
204
|
-
* Note: There are multiple simmilar function:
|
|
205
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
206
|
-
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
207
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
208
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
204
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
209
205
|
*
|
|
210
|
-
* @public exported from `@promptbook/
|
|
211
|
-
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
206
|
+
* @public exported from `@promptbook/core`
|
|
212
207
|
*/
|
|
213
|
-
|
|
214
|
-
if (isValidJsonString(markdown)) {
|
|
215
|
-
return markdown;
|
|
216
|
-
}
|
|
217
|
-
const codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
218
|
-
const jsonBlocks = codeBlocks.filter(({ content }) => isValidJsonString(content));
|
|
219
|
-
if (jsonBlocks.length === 0) {
|
|
220
|
-
throw new Error('There is no valid JSON block in the markdown');
|
|
221
|
-
}
|
|
222
|
-
if (jsonBlocks.length > 1) {
|
|
223
|
-
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
224
|
-
}
|
|
225
|
-
return jsonBlocks[0].content;
|
|
226
|
-
}
|
|
208
|
+
const NAME = `Promptbook`;
|
|
227
209
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
210
|
+
* Email of the responsible person
|
|
211
|
+
*
|
|
212
|
+
* @public exported from `@promptbook/core`
|
|
230
213
|
*/
|
|
231
|
-
|
|
214
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
232
215
|
/**
|
|
233
|
-
*
|
|
234
|
-
* No side effects.
|
|
216
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
235
217
|
*
|
|
236
|
-
*
|
|
218
|
+
* @public exported from `@promptbook/core`
|
|
219
|
+
*/
|
|
220
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
221
|
+
// <- TODO: [🐊] Pick the best claim
|
|
222
|
+
/**
|
|
223
|
+
* When the title is not provided, the default title is used
|
|
237
224
|
*
|
|
238
|
-
*
|
|
239
|
-
|
|
240
|
-
|
|
225
|
+
* @public exported from `@promptbook/core`
|
|
226
|
+
*/
|
|
227
|
+
const DEFAULT_BOOK_TITLE = `✨ Untitled Book`;
|
|
228
|
+
/**
|
|
229
|
+
* Maximum file size limit
|
|
241
230
|
*
|
|
242
|
-
* @
|
|
243
|
-
* @returns void
|
|
244
|
-
* @private within the repository
|
|
231
|
+
* @public exported from `@promptbook/core`
|
|
245
232
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",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`\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"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",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`\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"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",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`\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"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",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`\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"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",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`\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"}];
|
|
250
|
-
|
|
233
|
+
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
234
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
251
235
|
/**
|
|
252
|
-
*
|
|
236
|
+
* The maximum number of iterations for a loops
|
|
237
|
+
*
|
|
238
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
239
|
+
*/
|
|
240
|
+
const LOOP_LIMIT = 1000;
|
|
241
|
+
/**
|
|
242
|
+
* Strings to represent various values in the context of parameter values
|
|
253
243
|
*
|
|
254
244
|
* @public exported from `@promptbook/utils`
|
|
255
245
|
*/
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
246
|
+
const VALUE_STRINGS = {
|
|
247
|
+
empty: '(nothing; empty string)',
|
|
248
|
+
null: '(no value; null)',
|
|
249
|
+
undefined: '(unknown value; undefined)',
|
|
250
|
+
nan: '(not a number; NaN)',
|
|
251
|
+
infinity: '(infinity; ∞)',
|
|
252
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
253
|
+
unserializable: '(unserializable value)',
|
|
254
|
+
circular: '(circular JSON)',
|
|
255
|
+
};
|
|
266
256
|
/**
|
|
267
|
-
*
|
|
257
|
+
* Small number limit
|
|
268
258
|
*
|
|
269
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
270
259
|
* @public exported from `@promptbook/utils`
|
|
271
260
|
*/
|
|
272
|
-
|
|
273
|
-
if (typeof filename !== 'string') {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
if (filename.split('\n').length > 1) {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
if (filename.split(' ').length >
|
|
280
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
const filenameSlashes = filename.split('\\').join('/');
|
|
284
|
-
// Absolute Unix path: /hello.txt
|
|
285
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
286
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
// Absolute Windows path: /hello.txt
|
|
290
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
291
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
// Relative path: ./hello.txt
|
|
295
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
296
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
// Allow paths like foo/hello
|
|
300
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
301
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
// Allow paths like hello.book
|
|
305
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
306
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
261
|
+
const SMALL_NUMBER = 0.001;
|
|
311
262
|
/**
|
|
312
|
-
*
|
|
263
|
+
* Short time interval to prevent race conditions in milliseconds
|
|
264
|
+
*
|
|
265
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
313
266
|
*/
|
|
314
|
-
|
|
267
|
+
const IMMEDIATE_TIME = 10;
|
|
315
268
|
/**
|
|
316
|
-
*
|
|
269
|
+
* The maximum length of the (generated) filename
|
|
317
270
|
*
|
|
318
|
-
*
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
271
|
+
* @public exported from `@promptbook/core`
|
|
272
|
+
*/
|
|
273
|
+
const MAX_FILENAME_LENGTH = 30;
|
|
274
|
+
/**
|
|
275
|
+
* Strategy for caching the intermediate results for knowledge sources
|
|
322
276
|
*
|
|
323
|
-
* @public exported from `@promptbook/
|
|
277
|
+
* @public exported from `@promptbook/core`
|
|
324
278
|
*/
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
try {
|
|
330
|
-
if (url.startsWith('blob:')) {
|
|
331
|
-
url = url.replace(/^blob:/, '');
|
|
332
|
-
}
|
|
333
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
334
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
catch (error) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
279
|
+
const DEFAULT_INTERMEDIATE_FILES_STRATEGY = 'HIDE_AND_KEEP';
|
|
280
|
+
// <- TODO: [😡] Change to 'VISIBLE'
|
|
344
281
|
/**
|
|
345
|
-
*
|
|
346
|
-
* 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.
|
|
282
|
+
* The maximum number of (LLM) tasks running in parallel
|
|
347
283
|
*
|
|
348
|
-
* @param {string} pipelineString the candidate for a pipeline string
|
|
349
|
-
* @returns {PipelineString} the same string as input, but validated as valid
|
|
350
|
-
* @throws {ParseError} if the string is not a valid pipeline string
|
|
351
284
|
* @public exported from `@promptbook/core`
|
|
352
285
|
*/
|
|
353
|
-
|
|
354
|
-
if (isValidJsonString(pipelineString)) {
|
|
355
|
-
throw new ParseError('Expected a book, but got a JSON string');
|
|
356
|
-
}
|
|
357
|
-
else if (isValidUrl(pipelineString)) {
|
|
358
|
-
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
359
|
-
}
|
|
360
|
-
else if (isValidFilePath(pipelineString)) {
|
|
361
|
-
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
362
|
-
}
|
|
363
|
-
else if (isValidEmail(pipelineString)) {
|
|
364
|
-
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
365
|
-
}
|
|
366
|
-
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
367
|
-
return pipelineString;
|
|
368
|
-
}
|
|
286
|
+
const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
369
287
|
/**
|
|
370
|
-
*
|
|
288
|
+
* The maximum number of attempts to execute LLM task before giving up
|
|
289
|
+
*
|
|
290
|
+
* @public exported from `@promptbook/core`
|
|
371
291
|
*/
|
|
372
|
-
|
|
292
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
293
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
294
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
373
295
|
/**
|
|
374
|
-
*
|
|
296
|
+
* Where to store the temporary downloads
|
|
375
297
|
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* @
|
|
298
|
+
* Note: When the folder does not exist, it is created recursively
|
|
299
|
+
*
|
|
300
|
+
* @public exported from `@promptbook/core`
|
|
379
301
|
*/
|
|
380
|
-
|
|
381
|
-
try {
|
|
382
|
-
return prettier.format(content, {
|
|
383
|
-
parser: 'markdown',
|
|
384
|
-
plugins: [parserHtml__default["default"]],
|
|
385
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
386
|
-
endOfLine: 'lf',
|
|
387
|
-
tabWidth: 4,
|
|
388
|
-
singleQuote: true,
|
|
389
|
-
trailingComma: 'all',
|
|
390
|
-
arrowParens: 'always',
|
|
391
|
-
printWidth: 120,
|
|
392
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
393
|
-
jsxBracketSameLine: false,
|
|
394
|
-
bracketSpacing: true,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
catch (error) {
|
|
398
|
-
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
399
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
400
|
-
error,
|
|
401
|
-
html: content,
|
|
402
|
-
});
|
|
403
|
-
return content;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
302
|
+
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
407
303
|
/**
|
|
408
|
-
*
|
|
304
|
+
* Where to store the scrape cache
|
|
305
|
+
*
|
|
306
|
+
* Note: When the folder does not exist, it is created recursively
|
|
409
307
|
*
|
|
410
|
-
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
411
|
-
* @param pipelineJson Promptbook in JSON format (.bookc)
|
|
412
|
-
* @returns Promptbook in string format (.book.md)
|
|
413
308
|
* @public exported from `@promptbook/core`
|
|
414
309
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
let pipelineString = `# ${title}`;
|
|
418
|
-
if (description) {
|
|
419
|
-
pipelineString += '\n\n';
|
|
420
|
-
pipelineString += description;
|
|
421
|
-
}
|
|
422
|
-
const commands = [];
|
|
423
|
-
if (pipelineUrl) {
|
|
424
|
-
commands.push(`PIPELINE URL ${pipelineUrl}`);
|
|
425
|
-
}
|
|
426
|
-
if (bookVersion !== `undefined`) {
|
|
427
|
-
commands.push(`BOOK VERSION ${bookVersion}`);
|
|
428
|
-
}
|
|
429
|
-
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
430
|
-
pipelineString = prettifyMarkdown(pipelineString);
|
|
431
|
-
for (const parameter of parameters.filter(({ isInput }) => isInput)) {
|
|
432
|
-
commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
433
|
-
}
|
|
434
|
-
for (const parameter of parameters.filter(({ isOutput }) => isOutput)) {
|
|
435
|
-
commands.push(`OUTPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
436
|
-
}
|
|
437
|
-
pipelineString += '\n\n';
|
|
438
|
-
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
439
|
-
for (const task of tasks) {
|
|
440
|
-
const {
|
|
441
|
-
/* Note: Not using:> name, */
|
|
442
|
-
title, description,
|
|
443
|
-
/* Note: dependentParameterNames, */
|
|
444
|
-
jokerParameterNames: jokers, taskType, content, postprocessingFunctionNames: postprocessing, expectations, format, resultingParameterName, } = task;
|
|
445
|
-
pipelineString += '\n\n';
|
|
446
|
-
pipelineString += `## ${title}`;
|
|
447
|
-
if (description) {
|
|
448
|
-
pipelineString += '\n\n';
|
|
449
|
-
pipelineString += description;
|
|
450
|
-
}
|
|
451
|
-
const commands = [];
|
|
452
|
-
let contentLanguage = 'text';
|
|
453
|
-
if (taskType === 'PROMPT_TASK') {
|
|
454
|
-
const { modelRequirements } = task;
|
|
455
|
-
const { modelName, modelVariant } = modelRequirements || {};
|
|
456
|
-
// Note: Do nothing, it is default
|
|
457
|
-
// commands.push(`PROMPT`);
|
|
458
|
-
if (modelVariant) {
|
|
459
|
-
commands.push(`MODEL VARIANT ${capitalize(modelVariant)}`);
|
|
460
|
-
}
|
|
461
|
-
if (modelName) {
|
|
462
|
-
commands.push(`MODEL NAME \`${modelName}\``);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
else if (taskType === 'SIMPLE_TASK') {
|
|
466
|
-
commands.push(`SIMPLE TEMPLATE`);
|
|
467
|
-
// Note: Nothing special here
|
|
468
|
-
}
|
|
469
|
-
else if (taskType === 'SCRIPT_TASK') {
|
|
470
|
-
commands.push(`SCRIPT`);
|
|
471
|
-
if (task.contentLanguage) {
|
|
472
|
-
contentLanguage = task.contentLanguage;
|
|
473
|
-
}
|
|
474
|
-
else {
|
|
475
|
-
contentLanguage = '';
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
else if (taskType === 'DIALOG_TASK') {
|
|
479
|
-
commands.push(`DIALOG`);
|
|
480
|
-
// Note: Nothing special here
|
|
481
|
-
} // <- }else if([🅱]
|
|
482
|
-
if (jokers) {
|
|
483
|
-
for (const joker of jokers) {
|
|
484
|
-
commands.push(`JOKER {${joker}}`);
|
|
485
|
-
}
|
|
486
|
-
} /* not else */
|
|
487
|
-
if (postprocessing) {
|
|
488
|
-
for (const postprocessingFunctionName of postprocessing) {
|
|
489
|
-
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
490
|
-
}
|
|
491
|
-
} /* not else */
|
|
492
|
-
if (expectations) {
|
|
493
|
-
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
494
|
-
if (min === max) {
|
|
495
|
-
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
if (min !== undefined) {
|
|
499
|
-
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
500
|
-
} /* not else */
|
|
501
|
-
if (max !== undefined) {
|
|
502
|
-
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
} /* not else */
|
|
507
|
-
if (format) {
|
|
508
|
-
if (format === 'JSON') {
|
|
509
|
-
// TODO: @deprecated remove
|
|
510
|
-
commands.push(`FORMAT JSON`);
|
|
511
|
-
}
|
|
512
|
-
} /* not else */
|
|
513
|
-
pipelineString += '\n\n';
|
|
514
|
-
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
515
|
-
pipelineString += '\n\n';
|
|
516
|
-
pipelineString += '```' + contentLanguage;
|
|
517
|
-
pipelineString += '\n';
|
|
518
|
-
pipelineString += spaceTrim__default["default"](content);
|
|
519
|
-
// <- TODO: [main] !!3 Escape
|
|
520
|
-
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
521
|
-
pipelineString += '\n';
|
|
522
|
-
pipelineString += '```';
|
|
523
|
-
pipelineString += '\n\n';
|
|
524
|
-
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
525
|
-
}
|
|
526
|
-
return validatePipelineString(pipelineString);
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* @private internal utility of `pipelineJsonToString`
|
|
530
|
-
*/
|
|
531
|
-
function taskParameterJsonToString(taskParameterJson) {
|
|
532
|
-
const { name, description } = taskParameterJson;
|
|
533
|
-
let parameterString = `{${name}}`;
|
|
534
|
-
if (description) {
|
|
535
|
-
parameterString = `${parameterString} ${description}`;
|
|
536
|
-
}
|
|
537
|
-
return parameterString;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
541
|
-
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
542
|
-
* TODO: [🏛] Maybe make some markdown builder
|
|
543
|
-
* TODO: [🏛] Escape all
|
|
544
|
-
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
545
|
-
*/
|
|
546
|
-
|
|
310
|
+
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
311
|
+
// <- TODO: [🧜♂️]
|
|
547
312
|
/**
|
|
548
|
-
*
|
|
549
|
-
* No side effects.
|
|
550
|
-
*
|
|
551
|
-
* Note: It can be usefull for:
|
|
552
|
-
*
|
|
553
|
-
* 1) Leveling indentation
|
|
554
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
313
|
+
* @@@
|
|
555
314
|
*
|
|
556
|
-
* @
|
|
557
|
-
* @returns the same values
|
|
558
|
-
* @private within the repository
|
|
315
|
+
* @public exported from `@promptbook/core`
|
|
559
316
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
|
|
317
|
+
const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
318
|
+
delimiter: ',',
|
|
319
|
+
quoteChar: '"',
|
|
320
|
+
newline: '\n',
|
|
321
|
+
skipEmptyLines: true,
|
|
322
|
+
});
|
|
567
323
|
/**
|
|
568
|
-
*
|
|
324
|
+
* @@@
|
|
569
325
|
*
|
|
570
|
-
* @
|
|
326
|
+
* @public exported from `@promptbook/core`
|
|
571
327
|
*/
|
|
572
|
-
|
|
328
|
+
let DEFAULT_IS_VERBOSE = false;
|
|
573
329
|
/**
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
* TODO: [🗽] Unite branding and make single place for it
|
|
330
|
+
* @@@
|
|
577
331
|
*
|
|
578
332
|
* @public exported from `@promptbook/core`
|
|
579
333
|
*/
|
|
580
|
-
const
|
|
334
|
+
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
581
335
|
/**
|
|
582
|
-
*
|
|
336
|
+
* @@@
|
|
583
337
|
*
|
|
584
|
-
* @
|
|
338
|
+
* @private within the repository
|
|
585
339
|
*/
|
|
586
|
-
const
|
|
340
|
+
const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
341
|
+
/**/
|
|
342
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
343
|
+
true);
|
|
587
344
|
/**
|
|
588
|
-
*
|
|
345
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
346
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Make error report URL for the given error
|
|
589
351
|
*
|
|
590
|
-
* @
|
|
352
|
+
* @private private within the repository
|
|
591
353
|
*/
|
|
592
|
-
|
|
354
|
+
function getErrorReportUrl(error) {
|
|
355
|
+
const report = {
|
|
356
|
+
title: `🐜 Error report from ${NAME}`,
|
|
357
|
+
body: spaceTrim__default["default"]((block) => `
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
361
|
+
|
|
362
|
+
\`\`\`
|
|
363
|
+
${block(error.message || '(no error message)')}
|
|
364
|
+
\`\`\`
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
## More info:
|
|
368
|
+
|
|
369
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
370
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
371
|
+
- **Time:** ${new Date().toISOString()}
|
|
372
|
+
|
|
373
|
+
<details>
|
|
374
|
+
<summary>Stack trace:</summary>
|
|
375
|
+
|
|
376
|
+
## Stack trace:
|
|
377
|
+
|
|
378
|
+
\`\`\`stacktrace
|
|
379
|
+
${block(error.stack || '(empty)')}
|
|
380
|
+
\`\`\`
|
|
381
|
+
</details>
|
|
382
|
+
|
|
383
|
+
`),
|
|
384
|
+
};
|
|
385
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
386
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
387
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
388
|
+
reportUrl.searchParams.set('title', report.title);
|
|
389
|
+
reportUrl.searchParams.set('body', report.body);
|
|
390
|
+
return reportUrl;
|
|
391
|
+
}
|
|
392
|
+
|
|
593
393
|
/**
|
|
594
|
-
*
|
|
394
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
595
395
|
*
|
|
596
396
|
* @public exported from `@promptbook/core`
|
|
597
397
|
*/
|
|
598
|
-
|
|
398
|
+
class UnexpectedError extends Error {
|
|
399
|
+
constructor(message) {
|
|
400
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
401
|
+
${block(message)}
|
|
402
|
+
|
|
403
|
+
Note: This error should not happen.
|
|
404
|
+
It's probbably a bug in the pipeline collection
|
|
405
|
+
|
|
406
|
+
Please report issue:
|
|
407
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
408
|
+
|
|
409
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
410
|
+
|
|
411
|
+
`));
|
|
412
|
+
this.name = 'UnexpectedError';
|
|
413
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
599
417
|
/**
|
|
600
|
-
*
|
|
418
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
601
419
|
*
|
|
602
420
|
* @public exported from `@promptbook/core`
|
|
603
421
|
*/
|
|
604
|
-
|
|
605
|
-
|
|
422
|
+
class WrappedError extends Error {
|
|
423
|
+
constructor(whatWasThrown) {
|
|
424
|
+
const tag = `[🤮]`;
|
|
425
|
+
console.error(tag, whatWasThrown);
|
|
426
|
+
super(spaceTrim.spaceTrim(`
|
|
427
|
+
Non-Error object was thrown
|
|
428
|
+
|
|
429
|
+
Note: Look for ${tag} in the console for more details
|
|
430
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
431
|
+
`));
|
|
432
|
+
this.name = 'WrappedError';
|
|
433
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
606
437
|
/**
|
|
607
|
-
*
|
|
438
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
608
439
|
*
|
|
609
|
-
* @
|
|
440
|
+
* @param whatWasThrown Any object that was thrown
|
|
441
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
442
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
443
|
+
*
|
|
444
|
+
* @private within the repository
|
|
610
445
|
*/
|
|
611
|
-
|
|
446
|
+
function assertsError(whatWasThrown) {
|
|
447
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
448
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
449
|
+
const wrappedError = whatWasThrown;
|
|
450
|
+
throw wrappedError;
|
|
451
|
+
}
|
|
452
|
+
// Case 2: Handle unexpected errors
|
|
453
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
454
|
+
const unexpectedError = whatWasThrown;
|
|
455
|
+
throw unexpectedError;
|
|
456
|
+
}
|
|
457
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
458
|
+
if (whatWasThrown instanceof Error) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
462
|
+
throw new WrappedError(whatWasThrown);
|
|
463
|
+
}
|
|
464
|
+
|
|
612
465
|
/**
|
|
613
|
-
*
|
|
466
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
614
467
|
*
|
|
615
468
|
* @public exported from `@promptbook/utils`
|
|
616
469
|
*/
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
470
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
471
|
+
try {
|
|
472
|
+
JSON.parse(value);
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
assertsError(error);
|
|
477
|
+
if (error.message.includes('Unexpected token')) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
626
484
|
/**
|
|
627
|
-
*
|
|
485
|
+
* Extracts extracts exactly one valid JSON code block
|
|
628
486
|
*
|
|
629
|
-
*
|
|
487
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
488
|
+
* - When there is no JSON code block the function throws a `ParseError`
|
|
489
|
+
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
490
|
+
*
|
|
491
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
492
|
+
* Note: There are multiple simmilar function:
|
|
493
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
494
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
495
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
496
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
497
|
+
*
|
|
498
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
499
|
+
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
630
500
|
*/
|
|
631
|
-
|
|
501
|
+
function extractJsonBlock(markdown) {
|
|
502
|
+
if (isValidJsonString(markdown)) {
|
|
503
|
+
return markdown;
|
|
504
|
+
}
|
|
505
|
+
const codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
506
|
+
const jsonBlocks = codeBlocks.filter(({ content }) => isValidJsonString(content));
|
|
507
|
+
if (jsonBlocks.length === 0) {
|
|
508
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
509
|
+
}
|
|
510
|
+
if (jsonBlocks.length > 1) {
|
|
511
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
512
|
+
}
|
|
513
|
+
return jsonBlocks[0].content;
|
|
514
|
+
}
|
|
632
515
|
/**
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
516
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
517
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
636
518
|
*/
|
|
637
|
-
|
|
519
|
+
|
|
638
520
|
/**
|
|
639
|
-
*
|
|
521
|
+
* Just says that the variable is not used but should be kept
|
|
522
|
+
* No side effects.
|
|
640
523
|
*
|
|
641
|
-
*
|
|
524
|
+
* Note: It can be usefull for:
|
|
525
|
+
*
|
|
526
|
+
* 1) Suppressing eager optimization of unused imports
|
|
527
|
+
* 2) Suppressing eslint errors of unused variables in the tests
|
|
528
|
+
* 3) Keeping the type of the variable for type testing
|
|
529
|
+
*
|
|
530
|
+
* @param value any values
|
|
531
|
+
* @returns void
|
|
532
|
+
* @private within the repository
|
|
642
533
|
*/
|
|
643
|
-
|
|
534
|
+
function keepUnused(...valuesToKeep) {
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",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`\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"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",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`\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"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",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`\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"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",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`\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"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",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`\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"}];
|
|
538
|
+
|
|
644
539
|
/**
|
|
645
|
-
*
|
|
540
|
+
* Checks if value is valid email
|
|
646
541
|
*
|
|
647
|
-
* @public exported from `@promptbook/
|
|
542
|
+
* @public exported from `@promptbook/utils`
|
|
648
543
|
*/
|
|
649
|
-
|
|
650
|
-
|
|
544
|
+
function isValidEmail(email) {
|
|
545
|
+
if (typeof email !== 'string') {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
if (email.split('\n').length > 1) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
return /^.+@.+\..+$/.test(email);
|
|
552
|
+
}
|
|
553
|
+
|
|
651
554
|
/**
|
|
652
|
-
*
|
|
555
|
+
* Tests if given string is valid URL.
|
|
653
556
|
*
|
|
654
|
-
*
|
|
557
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
558
|
+
* @public exported from `@promptbook/utils`
|
|
655
559
|
*/
|
|
656
|
-
|
|
560
|
+
function isValidFilePath(filename) {
|
|
561
|
+
if (typeof filename !== 'string') {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
if (filename.split('\n').length > 1) {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
if (filename.split(' ').length >
|
|
568
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
const filenameSlashes = filename.split('\\').join('/');
|
|
572
|
+
// Absolute Unix path: /hello.txt
|
|
573
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
574
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
// Absolute Windows path: /hello.txt
|
|
578
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
579
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
// Relative path: ./hello.txt
|
|
583
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
584
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
// Allow paths like foo/hello
|
|
588
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
589
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
// Allow paths like hello.book
|
|
593
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
594
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
657
599
|
/**
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
* @public exported from `@promptbook/core`
|
|
600
|
+
* TODO: [🍏] Implement for MacOs
|
|
661
601
|
*/
|
|
662
|
-
|
|
663
|
-
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
602
|
+
|
|
664
603
|
/**
|
|
665
|
-
*
|
|
604
|
+
* Tests if given string is valid URL.
|
|
666
605
|
*
|
|
667
|
-
* Note:
|
|
606
|
+
* Note: Dataurl are considered perfectly valid.
|
|
607
|
+
* Note: There are two simmilar functions:
|
|
608
|
+
* - `isValidUrl` which tests any URL
|
|
609
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
668
610
|
*
|
|
669
|
-
* @public exported from `@promptbook/
|
|
611
|
+
* @public exported from `@promptbook/utils`
|
|
670
612
|
*/
|
|
671
|
-
|
|
613
|
+
function isValidUrl(url) {
|
|
614
|
+
if (typeof url !== 'string') {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
if (url.startsWith('blob:')) {
|
|
619
|
+
url = url.replace(/^blob:/, '');
|
|
620
|
+
}
|
|
621
|
+
const urlObject = new URL(url /* because fail is handled */);
|
|
622
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
catch (error) {
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
672
632
|
/**
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
* Note: When the folder does not exist, it is created recursively
|
|
633
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
634
|
+
* 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.
|
|
676
635
|
*
|
|
636
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
637
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
638
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
677
639
|
* @public exported from `@promptbook/core`
|
|
678
640
|
*/
|
|
679
|
-
|
|
680
|
-
|
|
641
|
+
function validatePipelineString(pipelineString) {
|
|
642
|
+
if (isValidJsonString(pipelineString)) {
|
|
643
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
644
|
+
}
|
|
645
|
+
else if (isValidUrl(pipelineString)) {
|
|
646
|
+
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
647
|
+
}
|
|
648
|
+
else if (isValidFilePath(pipelineString)) {
|
|
649
|
+
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
650
|
+
}
|
|
651
|
+
else if (isValidEmail(pipelineString)) {
|
|
652
|
+
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
653
|
+
}
|
|
654
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
655
|
+
return pipelineString;
|
|
656
|
+
}
|
|
681
657
|
/**
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
* @public exported from `@promptbook/core`
|
|
658
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
685
659
|
*/
|
|
686
|
-
|
|
687
|
-
delimiter: ',',
|
|
688
|
-
quoteChar: '"',
|
|
689
|
-
newline: '\n',
|
|
690
|
-
skipEmptyLines: true,
|
|
691
|
-
});
|
|
660
|
+
|
|
692
661
|
/**
|
|
693
|
-
*
|
|
662
|
+
* Prettify the html code
|
|
694
663
|
*
|
|
695
|
-
* @
|
|
664
|
+
* @param content raw html code
|
|
665
|
+
* @returns formatted html code
|
|
666
|
+
* @private withing the package because of HUGE size of prettier dependency
|
|
696
667
|
*/
|
|
697
|
-
|
|
668
|
+
function prettifyMarkdown(content) {
|
|
669
|
+
try {
|
|
670
|
+
return prettier.format(content, {
|
|
671
|
+
parser: 'markdown',
|
|
672
|
+
plugins: [parserHtml__default["default"]],
|
|
673
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
674
|
+
endOfLine: 'lf',
|
|
675
|
+
tabWidth: 4,
|
|
676
|
+
singleQuote: true,
|
|
677
|
+
trailingComma: 'all',
|
|
678
|
+
arrowParens: 'always',
|
|
679
|
+
printWidth: 120,
|
|
680
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
681
|
+
jsxBracketSameLine: false,
|
|
682
|
+
bracketSpacing: true,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
catch (error) {
|
|
686
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
687
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
688
|
+
error,
|
|
689
|
+
html: content,
|
|
690
|
+
});
|
|
691
|
+
return content;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
698
695
|
/**
|
|
699
|
-
*
|
|
696
|
+
* Converts promptbook in JSON format to string format
|
|
700
697
|
*
|
|
698
|
+
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
699
|
+
* @param pipelineJson Promptbook in JSON format (.bookc)
|
|
700
|
+
* @returns Promptbook in string format (.book.md)
|
|
701
701
|
* @public exported from `@promptbook/core`
|
|
702
702
|
*/
|
|
703
|
-
|
|
703
|
+
function pipelineJsonToString(pipelineJson) {
|
|
704
|
+
const { title, pipelineUrl, bookVersion, description, parameters, tasks } = pipelineJson;
|
|
705
|
+
let pipelineString = `# ${title}`;
|
|
706
|
+
if (description) {
|
|
707
|
+
pipelineString += '\n\n';
|
|
708
|
+
pipelineString += description;
|
|
709
|
+
}
|
|
710
|
+
const commands = [];
|
|
711
|
+
if (pipelineUrl) {
|
|
712
|
+
commands.push(`PIPELINE URL ${pipelineUrl}`);
|
|
713
|
+
}
|
|
714
|
+
if (bookVersion !== `undefined`) {
|
|
715
|
+
commands.push(`BOOK VERSION ${bookVersion}`);
|
|
716
|
+
}
|
|
717
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
718
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
719
|
+
for (const parameter of parameters.filter(({ isInput }) => isInput)) {
|
|
720
|
+
commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
721
|
+
}
|
|
722
|
+
for (const parameter of parameters.filter(({ isOutput }) => isOutput)) {
|
|
723
|
+
commands.push(`OUTPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
724
|
+
}
|
|
725
|
+
pipelineString += '\n\n';
|
|
726
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
727
|
+
for (const task of tasks) {
|
|
728
|
+
const {
|
|
729
|
+
/* Note: Not using:> name, */
|
|
730
|
+
title, description,
|
|
731
|
+
/* Note: dependentParameterNames, */
|
|
732
|
+
jokerParameterNames: jokers, taskType, content, postprocessingFunctionNames: postprocessing, expectations, format, resultingParameterName, } = task;
|
|
733
|
+
pipelineString += '\n\n';
|
|
734
|
+
pipelineString += `## ${title}`;
|
|
735
|
+
if (description) {
|
|
736
|
+
pipelineString += '\n\n';
|
|
737
|
+
pipelineString += description;
|
|
738
|
+
}
|
|
739
|
+
const commands = [];
|
|
740
|
+
let contentLanguage = 'text';
|
|
741
|
+
if (taskType === 'PROMPT_TASK') {
|
|
742
|
+
const { modelRequirements } = task;
|
|
743
|
+
const { modelName, modelVariant } = modelRequirements || {};
|
|
744
|
+
// Note: Do nothing, it is default
|
|
745
|
+
// commands.push(`PROMPT`);
|
|
746
|
+
if (modelVariant) {
|
|
747
|
+
commands.push(`MODEL VARIANT ${capitalize(modelVariant)}`);
|
|
748
|
+
}
|
|
749
|
+
if (modelName) {
|
|
750
|
+
commands.push(`MODEL NAME \`${modelName}\``);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
754
|
+
commands.push(`SIMPLE TEMPLATE`);
|
|
755
|
+
// Note: Nothing special here
|
|
756
|
+
}
|
|
757
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
758
|
+
commands.push(`SCRIPT`);
|
|
759
|
+
if (task.contentLanguage) {
|
|
760
|
+
contentLanguage = task.contentLanguage;
|
|
761
|
+
}
|
|
762
|
+
else {
|
|
763
|
+
contentLanguage = '';
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
767
|
+
commands.push(`DIALOG`);
|
|
768
|
+
// Note: Nothing special here
|
|
769
|
+
} // <- }else if([🅱]
|
|
770
|
+
if (jokers) {
|
|
771
|
+
for (const joker of jokers) {
|
|
772
|
+
commands.push(`JOKER {${joker}}`);
|
|
773
|
+
}
|
|
774
|
+
} /* not else */
|
|
775
|
+
if (postprocessing) {
|
|
776
|
+
for (const postprocessingFunctionName of postprocessing) {
|
|
777
|
+
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
778
|
+
}
|
|
779
|
+
} /* not else */
|
|
780
|
+
if (expectations) {
|
|
781
|
+
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
782
|
+
if (min === max) {
|
|
783
|
+
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
if (min !== undefined) {
|
|
787
|
+
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
788
|
+
} /* not else */
|
|
789
|
+
if (max !== undefined) {
|
|
790
|
+
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
} /* not else */
|
|
795
|
+
if (format) {
|
|
796
|
+
if (format === 'JSON') {
|
|
797
|
+
// TODO: @deprecated remove
|
|
798
|
+
commands.push(`FORMAT JSON`);
|
|
799
|
+
}
|
|
800
|
+
} /* not else */
|
|
801
|
+
pipelineString += '\n\n';
|
|
802
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
803
|
+
pipelineString += '\n\n';
|
|
804
|
+
pipelineString += '```' + contentLanguage;
|
|
805
|
+
pipelineString += '\n';
|
|
806
|
+
pipelineString += spaceTrim__default["default"](content);
|
|
807
|
+
// <- TODO: [main] !!3 Escape
|
|
808
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
809
|
+
pipelineString += '\n';
|
|
810
|
+
pipelineString += '```';
|
|
811
|
+
pipelineString += '\n\n';
|
|
812
|
+
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
813
|
+
}
|
|
814
|
+
return validatePipelineString(pipelineString);
|
|
815
|
+
}
|
|
704
816
|
/**
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
* @private within the repository
|
|
817
|
+
* @private internal utility of `pipelineJsonToString`
|
|
708
818
|
*/
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
819
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
820
|
+
const { name, description } = taskParameterJson;
|
|
821
|
+
let parameterString = `{${name}}`;
|
|
822
|
+
if (description) {
|
|
823
|
+
parameterString = `${parameterString} ${description}`;
|
|
824
|
+
}
|
|
825
|
+
return parameterString;
|
|
826
|
+
}
|
|
713
827
|
/**
|
|
714
|
-
*
|
|
715
|
-
* TODO: [🧠]
|
|
828
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
829
|
+
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
830
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
831
|
+
* TODO: [🏛] Escape all
|
|
832
|
+
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
716
833
|
*/
|
|
717
834
|
|
|
718
835
|
/**
|
|
@@ -757,74 +874,6 @@
|
|
|
757
874
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
758
875
|
*/
|
|
759
876
|
|
|
760
|
-
/**
|
|
761
|
-
* Make error report URL for the given error
|
|
762
|
-
*
|
|
763
|
-
* @private private within the repository
|
|
764
|
-
*/
|
|
765
|
-
function getErrorReportUrl(error) {
|
|
766
|
-
const report = {
|
|
767
|
-
title: `🐜 Error report from ${NAME}`,
|
|
768
|
-
body: spaceTrim__default["default"]((block) => `
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
772
|
-
|
|
773
|
-
\`\`\`
|
|
774
|
-
${block(error.message || '(no error message)')}
|
|
775
|
-
\`\`\`
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
## More info:
|
|
779
|
-
|
|
780
|
-
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
781
|
-
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
782
|
-
- **Time:** ${new Date().toISOString()}
|
|
783
|
-
|
|
784
|
-
<details>
|
|
785
|
-
<summary>Stack trace:</summary>
|
|
786
|
-
|
|
787
|
-
## Stack trace:
|
|
788
|
-
|
|
789
|
-
\`\`\`stacktrace
|
|
790
|
-
${block(error.stack || '(empty)')}
|
|
791
|
-
\`\`\`
|
|
792
|
-
</details>
|
|
793
|
-
|
|
794
|
-
`),
|
|
795
|
-
};
|
|
796
|
-
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
797
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
798
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
799
|
-
reportUrl.searchParams.set('title', report.title);
|
|
800
|
-
reportUrl.searchParams.set('body', report.body);
|
|
801
|
-
return reportUrl;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
806
|
-
*
|
|
807
|
-
* @public exported from `@promptbook/core`
|
|
808
|
-
*/
|
|
809
|
-
class UnexpectedError extends Error {
|
|
810
|
-
constructor(message) {
|
|
811
|
-
super(spaceTrim.spaceTrim((block) => `
|
|
812
|
-
${block(message)}
|
|
813
|
-
|
|
814
|
-
Note: This error should not happen.
|
|
815
|
-
It's probbably a bug in the pipeline collection
|
|
816
|
-
|
|
817
|
-
Please report issue:
|
|
818
|
-
${block(getErrorReportUrl(new Error(message)).href)}
|
|
819
|
-
|
|
820
|
-
Or contact us on ${ADMIN_EMAIL}
|
|
821
|
-
|
|
822
|
-
`));
|
|
823
|
-
this.name = 'UnexpectedError';
|
|
824
|
-
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
|
|
828
877
|
/**
|
|
829
878
|
* Checks if the value is [🚉] serializable as JSON
|
|
830
879
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -916,9 +965,7 @@
|
|
|
916
965
|
JSON.stringify(value); // <- TODO: [0]
|
|
917
966
|
}
|
|
918
967
|
catch (error) {
|
|
919
|
-
|
|
920
|
-
throw error;
|
|
921
|
-
}
|
|
968
|
+
assertsError(error);
|
|
922
969
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
923
970
|
\`${name}\` is not serializable
|
|
924
971
|
|
|
@@ -1707,7 +1754,7 @@
|
|
|
1707
1754
|
}
|
|
1708
1755
|
}
|
|
1709
1756
|
/**
|
|
1710
|
-
* TODO:
|
|
1757
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
1711
1758
|
*/
|
|
1712
1759
|
|
|
1713
1760
|
/**
|
|
@@ -1807,6 +1854,19 @@
|
|
|
1807
1854
|
}
|
|
1808
1855
|
}
|
|
1809
1856
|
|
|
1857
|
+
/**
|
|
1858
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1859
|
+
*
|
|
1860
|
+
* @public exported from `@promptbook/core`
|
|
1861
|
+
*/
|
|
1862
|
+
class AuthenticationError extends Error {
|
|
1863
|
+
constructor(message) {
|
|
1864
|
+
super(message);
|
|
1865
|
+
this.name = 'AuthenticationError';
|
|
1866
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1810
1870
|
/**
|
|
1811
1871
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1812
1872
|
*
|
|
@@ -1898,6 +1958,19 @@
|
|
|
1898
1958
|
}
|
|
1899
1959
|
}
|
|
1900
1960
|
|
|
1961
|
+
/**
|
|
1962
|
+
* Error thrown when a fetch request fails
|
|
1963
|
+
*
|
|
1964
|
+
* @public exported from `@promptbook/core`
|
|
1965
|
+
*/
|
|
1966
|
+
class PromptbookFetchError extends Error {
|
|
1967
|
+
constructor(message) {
|
|
1968
|
+
super(message);
|
|
1969
|
+
this.name = 'PromptbookFetchError';
|
|
1970
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1901
1974
|
/**
|
|
1902
1975
|
* Index of all custom errors
|
|
1903
1976
|
*
|
|
@@ -1918,7 +1991,10 @@
|
|
|
1918
1991
|
PipelineExecutionError,
|
|
1919
1992
|
PipelineLogicError,
|
|
1920
1993
|
PipelineUrlError,
|
|
1994
|
+
AuthenticationError,
|
|
1995
|
+
PromptbookFetchError,
|
|
1921
1996
|
UnexpectedError,
|
|
1997
|
+
WrappedError,
|
|
1922
1998
|
// TODO: [🪑]> VersionMismatchError,
|
|
1923
1999
|
};
|
|
1924
2000
|
/**
|
|
@@ -2057,8 +2133,8 @@
|
|
|
2057
2133
|
updatedAt = new Date();
|
|
2058
2134
|
errors.push(...executionResult.errors);
|
|
2059
2135
|
warnings.push(...executionResult.warnings);
|
|
2060
|
-
// <- TODO:
|
|
2061
|
-
// TODO: [🧠]
|
|
2136
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2137
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2062
2138
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2063
2139
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2064
2140
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2068,6 +2144,7 @@
|
|
|
2068
2144
|
partialResultSubject.next(executionResult);
|
|
2069
2145
|
}
|
|
2070
2146
|
catch (error) {
|
|
2147
|
+
assertsError(error);
|
|
2071
2148
|
status = 'ERROR';
|
|
2072
2149
|
errors.push(error);
|
|
2073
2150
|
partialResultSubject.error(error);
|
|
@@ -2134,6 +2211,10 @@
|
|
|
2134
2211
|
|
|
2135
2212
|
Cannot serialize error with name "${name}"
|
|
2136
2213
|
|
|
2214
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2215
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2216
|
+
|
|
2217
|
+
|
|
2137
2218
|
${block(stack || message)}
|
|
2138
2219
|
|
|
2139
2220
|
`));
|
|
@@ -2455,14 +2536,15 @@
|
|
|
2455
2536
|
}
|
|
2456
2537
|
}
|
|
2457
2538
|
catch (error) {
|
|
2458
|
-
|
|
2539
|
+
assertsError(error);
|
|
2540
|
+
if (error instanceof UnexpectedError) {
|
|
2459
2541
|
throw error;
|
|
2460
2542
|
}
|
|
2461
2543
|
errors.push({ llmExecutionTools, error });
|
|
2462
2544
|
}
|
|
2463
2545
|
}
|
|
2464
2546
|
if (errors.length === 1) {
|
|
2465
|
-
throw errors[0];
|
|
2547
|
+
throw errors[0].error;
|
|
2466
2548
|
}
|
|
2467
2549
|
else if (errors.length > 1) {
|
|
2468
2550
|
throw new PipelineExecutionError(
|
|
@@ -3296,17 +3378,22 @@
|
|
|
3296
3378
|
/**
|
|
3297
3379
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3298
3380
|
*
|
|
3299
|
-
* @
|
|
3381
|
+
* @public exported from `@promptbook/core`
|
|
3300
3382
|
*/
|
|
3301
|
-
const
|
|
3383
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3302
3384
|
try {
|
|
3303
|
-
return await fetch(
|
|
3385
|
+
return await fetch(urlOrRequest, init);
|
|
3304
3386
|
}
|
|
3305
3387
|
catch (error) {
|
|
3306
|
-
|
|
3307
|
-
|
|
3388
|
+
assertsError(error);
|
|
3389
|
+
let url;
|
|
3390
|
+
if (typeof urlOrRequest === 'string') {
|
|
3391
|
+
url = urlOrRequest;
|
|
3308
3392
|
}
|
|
3309
|
-
|
|
3393
|
+
else if (urlOrRequest instanceof Request) {
|
|
3394
|
+
url = urlOrRequest.url;
|
|
3395
|
+
}
|
|
3396
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
3310
3397
|
Can not fetch "${url}"
|
|
3311
3398
|
|
|
3312
3399
|
Fetch error:
|
|
@@ -3327,7 +3414,7 @@
|
|
|
3327
3414
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3328
3415
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3329
3416
|
var _a;
|
|
3330
|
-
const { fetch =
|
|
3417
|
+
const { fetch = promptbookFetch } = tools;
|
|
3331
3418
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3332
3419
|
let { name } = knowledgeSource;
|
|
3333
3420
|
const { rootDirname = null,
|
|
@@ -3529,9 +3616,7 @@
|
|
|
3529
3616
|
knowledgePreparedUnflatten[index] = pieces;
|
|
3530
3617
|
}
|
|
3531
3618
|
catch (error) {
|
|
3532
|
-
|
|
3533
|
-
throw error;
|
|
3534
|
-
}
|
|
3619
|
+
assertsError(error);
|
|
3535
3620
|
console.warn(error);
|
|
3536
3621
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3537
3622
|
}
|
|
@@ -3823,13 +3908,19 @@
|
|
|
3823
3908
|
return value.toISOString();
|
|
3824
3909
|
}
|
|
3825
3910
|
else {
|
|
3826
|
-
|
|
3911
|
+
try {
|
|
3912
|
+
return JSON.stringify(value);
|
|
3913
|
+
}
|
|
3914
|
+
catch (error) {
|
|
3915
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3916
|
+
return VALUE_STRINGS.circular;
|
|
3917
|
+
}
|
|
3918
|
+
throw error;
|
|
3919
|
+
}
|
|
3827
3920
|
}
|
|
3828
3921
|
}
|
|
3829
3922
|
catch (error) {
|
|
3830
|
-
|
|
3831
|
-
throw error;
|
|
3832
|
-
}
|
|
3923
|
+
assertsError(error);
|
|
3833
3924
|
console.error(error);
|
|
3834
3925
|
return VALUE_STRINGS.unserializable;
|
|
3835
3926
|
}
|
|
@@ -3886,9 +3977,7 @@
|
|
|
3886
3977
|
}
|
|
3887
3978
|
}
|
|
3888
3979
|
catch (error) {
|
|
3889
|
-
|
|
3890
|
-
throw error;
|
|
3891
|
-
}
|
|
3980
|
+
assertsError(error);
|
|
3892
3981
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3893
3982
|
Can not extract variables from the script
|
|
3894
3983
|
${block(error.stack || error.message)}
|
|
@@ -4651,9 +4740,7 @@
|
|
|
4651
4740
|
break scripts;
|
|
4652
4741
|
}
|
|
4653
4742
|
catch (error) {
|
|
4654
|
-
|
|
4655
|
-
throw error;
|
|
4656
|
-
}
|
|
4743
|
+
assertsError(error);
|
|
4657
4744
|
if (error instanceof UnexpectedError) {
|
|
4658
4745
|
throw error;
|
|
4659
4746
|
}
|
|
@@ -4723,9 +4810,7 @@
|
|
|
4723
4810
|
break scripts;
|
|
4724
4811
|
}
|
|
4725
4812
|
catch (error) {
|
|
4726
|
-
|
|
4727
|
-
throw error;
|
|
4728
|
-
}
|
|
4813
|
+
assertsError(error);
|
|
4729
4814
|
if (error instanceof UnexpectedError) {
|
|
4730
4815
|
throw error;
|
|
4731
4816
|
}
|
|
@@ -5346,9 +5431,7 @@
|
|
|
5346
5431
|
await Promise.all(resolving);
|
|
5347
5432
|
}
|
|
5348
5433
|
catch (error /* <- Note: [3] */) {
|
|
5349
|
-
|
|
5350
|
-
throw error;
|
|
5351
|
-
}
|
|
5434
|
+
assertsError(error);
|
|
5352
5435
|
// Note: No need to rethrow UnexpectedError
|
|
5353
5436
|
// if (error instanceof UnexpectedError) {
|
|
5354
5437
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|