@promptbook/core 0.89.0-2 → 0.89.0-21
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 +10 -6
- package/esm/index.es.js +523 -383
- 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 +18 -16
- 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/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 +532 -386
- 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/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-21';
|
|
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
|
|
@@ -159,236 +159,31 @@ class ParseError extends Error {
|
|
|
159
159
|
*/
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @public exported from `@promptbook/utils`
|
|
165
|
-
*/
|
|
166
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
167
|
-
try {
|
|
168
|
-
JSON.parse(value);
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
if (!(error instanceof Error)) {
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
if (error.message.includes('Unexpected token')) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
184
|
-
* 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.
|
|
185
|
-
*
|
|
186
|
-
* @param {string} pipelineString the candidate for a pipeline string
|
|
187
|
-
* @returns {PipelineString} the same string as input, but validated as valid
|
|
188
|
-
* @throws {ParseError} if the string is not a valid pipeline string
|
|
189
|
-
* @public exported from `@promptbook/core`
|
|
190
|
-
*/
|
|
191
|
-
function validatePipelineString(pipelineString) {
|
|
192
|
-
if (isValidJsonString(pipelineString)) {
|
|
193
|
-
throw new ParseError('Expected a book, but got a JSON string');
|
|
194
|
-
}
|
|
195
|
-
else if (isValidUrl(pipelineString)) {
|
|
196
|
-
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
197
|
-
}
|
|
198
|
-
else if (isValidFilePath(pipelineString)) {
|
|
199
|
-
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
200
|
-
}
|
|
201
|
-
else if (isValidEmail(pipelineString)) {
|
|
202
|
-
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
203
|
-
}
|
|
204
|
-
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
205
|
-
return pipelineString;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* TODO: [🧠][🈴] Where is the best location for this file
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Prettify the html code
|
|
213
|
-
*
|
|
214
|
-
* @param content raw html code
|
|
215
|
-
* @returns formatted html code
|
|
216
|
-
* @private withing the package because of HUGE size of prettier dependency
|
|
217
|
-
*/
|
|
218
|
-
function prettifyMarkdown(content) {
|
|
219
|
-
try {
|
|
220
|
-
return format(content, {
|
|
221
|
-
parser: 'markdown',
|
|
222
|
-
plugins: [parserHtml],
|
|
223
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
224
|
-
endOfLine: 'lf',
|
|
225
|
-
tabWidth: 4,
|
|
226
|
-
singleQuote: true,
|
|
227
|
-
trailingComma: 'all',
|
|
228
|
-
arrowParens: 'always',
|
|
229
|
-
printWidth: 120,
|
|
230
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
231
|
-
jsxBracketSameLine: false,
|
|
232
|
-
bracketSpacing: true,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
237
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
238
|
-
error,
|
|
239
|
-
html: content,
|
|
240
|
-
});
|
|
241
|
-
return content;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Makes first letter of a string uppercase
|
|
247
|
-
*
|
|
248
|
-
* @public exported from `@promptbook/utils`
|
|
249
|
-
*/
|
|
250
|
-
function capitalize(word) {
|
|
251
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Converts promptbook in JSON format to string format
|
|
162
|
+
* Available remote servers for the Promptbook
|
|
256
163
|
*
|
|
257
|
-
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
258
|
-
* @param pipelineJson Promptbook in JSON format (.bookc)
|
|
259
|
-
* @returns Promptbook in string format (.book.md)
|
|
260
164
|
* @public exported from `@promptbook/core`
|
|
261
165
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
for (const parameter of parameters.filter(({ isOutput }) => isOutput)) {
|
|
282
|
-
commands.push(`OUTPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
283
|
-
}
|
|
284
|
-
pipelineString += '\n\n';
|
|
285
|
-
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
286
|
-
for (const task of tasks) {
|
|
287
|
-
const {
|
|
288
|
-
/* Note: Not using:> name, */
|
|
289
|
-
title, description,
|
|
290
|
-
/* Note: dependentParameterNames, */
|
|
291
|
-
jokerParameterNames: jokers, taskType, content, postprocessingFunctionNames: postprocessing, expectations, format, resultingParameterName, } = task;
|
|
292
|
-
pipelineString += '\n\n';
|
|
293
|
-
pipelineString += `## ${title}`;
|
|
294
|
-
if (description) {
|
|
295
|
-
pipelineString += '\n\n';
|
|
296
|
-
pipelineString += description;
|
|
297
|
-
}
|
|
298
|
-
const commands = [];
|
|
299
|
-
let contentLanguage = 'text';
|
|
300
|
-
if (taskType === 'PROMPT_TASK') {
|
|
301
|
-
const { modelRequirements } = task;
|
|
302
|
-
const { modelName, modelVariant } = modelRequirements || {};
|
|
303
|
-
// Note: Do nothing, it is default
|
|
304
|
-
// commands.push(`PROMPT`);
|
|
305
|
-
if (modelVariant) {
|
|
306
|
-
commands.push(`MODEL VARIANT ${capitalize(modelVariant)}`);
|
|
307
|
-
}
|
|
308
|
-
if (modelName) {
|
|
309
|
-
commands.push(`MODEL NAME \`${modelName}\``);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
else if (taskType === 'SIMPLE_TASK') {
|
|
313
|
-
commands.push(`SIMPLE TEMPLATE`);
|
|
314
|
-
// Note: Nothing special here
|
|
315
|
-
}
|
|
316
|
-
else if (taskType === 'SCRIPT_TASK') {
|
|
317
|
-
commands.push(`SCRIPT`);
|
|
318
|
-
if (task.contentLanguage) {
|
|
319
|
-
contentLanguage = task.contentLanguage;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
contentLanguage = '';
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
else if (taskType === 'DIALOG_TASK') {
|
|
326
|
-
commands.push(`DIALOG`);
|
|
327
|
-
// Note: Nothing special here
|
|
328
|
-
} // <- }else if([🅱]
|
|
329
|
-
if (jokers) {
|
|
330
|
-
for (const joker of jokers) {
|
|
331
|
-
commands.push(`JOKER {${joker}}`);
|
|
332
|
-
}
|
|
333
|
-
} /* not else */
|
|
334
|
-
if (postprocessing) {
|
|
335
|
-
for (const postprocessingFunctionName of postprocessing) {
|
|
336
|
-
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
337
|
-
}
|
|
338
|
-
} /* not else */
|
|
339
|
-
if (expectations) {
|
|
340
|
-
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
341
|
-
if (min === max) {
|
|
342
|
-
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
if (min !== undefined) {
|
|
346
|
-
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
347
|
-
} /* not else */
|
|
348
|
-
if (max !== undefined) {
|
|
349
|
-
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
} /* not else */
|
|
354
|
-
if (format) {
|
|
355
|
-
if (format === 'JSON') {
|
|
356
|
-
// TODO: @deprecated remove
|
|
357
|
-
commands.push(`FORMAT JSON`);
|
|
358
|
-
}
|
|
359
|
-
} /* not else */
|
|
360
|
-
pipelineString += '\n\n';
|
|
361
|
-
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
362
|
-
pipelineString += '\n\n';
|
|
363
|
-
pipelineString += '```' + contentLanguage;
|
|
364
|
-
pipelineString += '\n';
|
|
365
|
-
pipelineString += spaceTrim(content);
|
|
366
|
-
// <- TODO: [main] !!3 Escape
|
|
367
|
-
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
368
|
-
pipelineString += '\n';
|
|
369
|
-
pipelineString += '```';
|
|
370
|
-
pipelineString += '\n\n';
|
|
371
|
-
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
372
|
-
}
|
|
373
|
-
return validatePipelineString(pipelineString);
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* @private internal utility of `pipelineJsonToString`
|
|
377
|
-
*/
|
|
378
|
-
function taskParameterJsonToString(taskParameterJson) {
|
|
379
|
-
const { name, description } = taskParameterJson;
|
|
380
|
-
let parameterString = `{${name}}`;
|
|
381
|
-
if (description) {
|
|
382
|
-
parameterString = `${parameterString} ${description}`;
|
|
383
|
-
}
|
|
384
|
-
return parameterString;
|
|
385
|
-
}
|
|
166
|
+
const REMOTE_SERVER_URLS = [
|
|
167
|
+
{
|
|
168
|
+
title: 'Promptbook',
|
|
169
|
+
description: `Servers of Promptbook.studio`,
|
|
170
|
+
owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
|
|
171
|
+
isAnonymousModeAllowed: true,
|
|
172
|
+
urls: [
|
|
173
|
+
'https://s5.ptbk.io/promptbook',
|
|
174
|
+
// Note: Servers 1-4 are not running
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
title: 'Pavol Promptbook Server',
|
|
179
|
+
description: `Personal server of Pavol Hejný with simple testing server, DO NOT USE IT FOR PRODUCTION`,
|
|
180
|
+
owner: 'Pavol Hejný <pavol@ptbk.io> (https://www.pavolhejny.com/)',
|
|
181
|
+
isAnonymousModeAllowed: true,
|
|
182
|
+
urls: ['https://api.pavolhejny.com/promptbook'],
|
|
183
|
+
},
|
|
184
|
+
];
|
|
386
185
|
/**
|
|
387
|
-
*
|
|
388
|
-
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
389
|
-
* TODO: [🏛] Maybe make some markdown builder
|
|
390
|
-
* TODO: [🏛] Escape all
|
|
391
|
-
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
186
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
392
187
|
*/
|
|
393
188
|
|
|
394
189
|
/**
|
|
@@ -446,22 +241,6 @@ const ADMIN_GITHUB_NAME = 'hejny';
|
|
|
446
241
|
*/
|
|
447
242
|
const CLAIM = `It's time for a paradigm shift. The future of software in plain English, French or Latin`;
|
|
448
243
|
// <- TODO: [🐊] Pick the best claim
|
|
449
|
-
/**
|
|
450
|
-
* Logo for the light theme
|
|
451
|
-
*
|
|
452
|
-
* TODO: [🗽] Unite branding and make single place for it
|
|
453
|
-
*
|
|
454
|
-
* @public exported from `@promptbook/core`
|
|
455
|
-
*/
|
|
456
|
-
const LOGO_LIGHT_SRC = `https://promptbook.studio/_next/static/media/promptbook-logo.b21f0c70.png`; // <- TODO: !!! Auto-update or remove
|
|
457
|
-
/**
|
|
458
|
-
* Logo for the dark theme
|
|
459
|
-
*
|
|
460
|
-
* TODO: [🗽] Unite branding and make single place for it
|
|
461
|
-
*
|
|
462
|
-
* @public exported from `@promptbook/core`
|
|
463
|
-
*/
|
|
464
|
-
const LOGO_DARK_SRC = `https://promptbook.studio/_next/static/media/promptbook-logo-white.09887cbc.png`; // <- TODO: !!! Auto-update or remove
|
|
465
244
|
/**
|
|
466
245
|
* When the title is not provided, the default title is used
|
|
467
246
|
*
|
|
@@ -512,6 +291,7 @@ const VALUE_STRINGS = {
|
|
|
512
291
|
infinity: '(infinity; ∞)',
|
|
513
292
|
negativeInfinity: '(negative infinity; -∞)',
|
|
514
293
|
unserializable: '(unserializable value)',
|
|
294
|
+
circular: '(circular JSON)',
|
|
515
295
|
};
|
|
516
296
|
/**
|
|
517
297
|
* Small number limit
|
|
@@ -572,6 +352,7 @@ const DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
|
|
|
572
352
|
*/
|
|
573
353
|
const DEFAULT_BOOKS_DIRNAME = './books';
|
|
574
354
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
355
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
575
356
|
/**
|
|
576
357
|
* Where to store the temporary downloads
|
|
577
358
|
*
|
|
@@ -596,6 +377,27 @@ const DEFAULT_EXECUTION_CACHE_DIRNAME = './.promptbook/execution-cache';
|
|
|
596
377
|
* @public exported from `@promptbook/core`
|
|
597
378
|
*/
|
|
598
379
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
380
|
+
/**
|
|
381
|
+
* Id of application for the CLI when using remote server
|
|
382
|
+
*
|
|
383
|
+
* @public exported from `@promptbook/core`
|
|
384
|
+
*/
|
|
385
|
+
const CLI_APP_ID = 'cli';
|
|
386
|
+
/**
|
|
387
|
+
* Id of application for the playground
|
|
388
|
+
*
|
|
389
|
+
* @public exported from `@promptbook/core`
|
|
390
|
+
*/
|
|
391
|
+
const PLAYGROUND_APP_ID = 'playground';
|
|
392
|
+
/*
|
|
393
|
+
TODO: [🌃]
|
|
394
|
+
/**
|
|
395
|
+
* Id of application for the wizzard when using remote server
|
|
396
|
+
*
|
|
397
|
+
* @public exported from `@promptbook/core`
|
|
398
|
+
* /
|
|
399
|
+
ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
|
|
400
|
+
*/
|
|
599
401
|
/**
|
|
600
402
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
601
403
|
*
|
|
@@ -612,17 +414,11 @@ const MOMENT_ARG_THRESHOLDS = {
|
|
|
612
414
|
ss: 3, // <- least number of seconds to be counted in seconds, minus 1. Must be set after setting the `s` unit or without setting the `s` unit.
|
|
613
415
|
};
|
|
614
416
|
/**
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
* @public exported from `@promptbook/core`
|
|
618
|
-
*/
|
|
619
|
-
const DEFAULT_REMOTE_URL = 'https://api.pavolhejny.com/';
|
|
620
|
-
/**
|
|
621
|
-
* @@@
|
|
417
|
+
* Default remote server URL for the Promptbook
|
|
622
418
|
*
|
|
623
419
|
* @public exported from `@promptbook/core`
|
|
624
420
|
*/
|
|
625
|
-
const
|
|
421
|
+
const DEFAULT_REMOTE_SERVER_URL = REMOTE_SERVER_URLS[0].urls[0];
|
|
626
422
|
// <- TODO: [🧜♂️]
|
|
627
423
|
/**
|
|
628
424
|
* @@@
|
|
@@ -652,29 +448,376 @@ function SET_IS_VERBOSE(isVerbose) {
|
|
|
652
448
|
DEFAULT_IS_VERBOSE = isVerbose;
|
|
653
449
|
}
|
|
654
450
|
/**
|
|
655
|
-
* @@@
|
|
656
|
-
*
|
|
657
|
-
* @public exported from `@promptbook/core`
|
|
658
|
-
*/
|
|
659
|
-
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
660
|
-
/**
|
|
661
|
-
* Function name for generated function via `ptbk make` to get the pipeline collection
|
|
662
|
-
*
|
|
663
|
-
* @public exported from `@promptbook/core`
|
|
664
|
-
*/
|
|
665
|
-
const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = `getPipelineCollection`;
|
|
666
|
-
/**
|
|
667
|
-
* @@@
|
|
668
|
-
*
|
|
669
|
-
* @private within the repository
|
|
451
|
+
* @@@
|
|
452
|
+
*
|
|
453
|
+
* @public exported from `@promptbook/core`
|
|
454
|
+
*/
|
|
455
|
+
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
456
|
+
/**
|
|
457
|
+
* Function name for generated function via `ptbk make` to get the pipeline collection
|
|
458
|
+
*
|
|
459
|
+
* @public exported from `@promptbook/core`
|
|
460
|
+
*/
|
|
461
|
+
const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = `getPipelineCollection`;
|
|
462
|
+
/**
|
|
463
|
+
* @@@
|
|
464
|
+
*
|
|
465
|
+
* @private within the repository
|
|
466
|
+
*/
|
|
467
|
+
const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
468
|
+
/**/
|
|
469
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
470
|
+
true);
|
|
471
|
+
/**
|
|
472
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
473
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Make error report URL for the given error
|
|
478
|
+
*
|
|
479
|
+
* @private private within the repository
|
|
480
|
+
*/
|
|
481
|
+
function getErrorReportUrl(error) {
|
|
482
|
+
const report = {
|
|
483
|
+
title: `🐜 Error report from ${NAME}`,
|
|
484
|
+
body: spaceTrim((block) => `
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
488
|
+
|
|
489
|
+
\`\`\`
|
|
490
|
+
${block(error.message || '(no error message)')}
|
|
491
|
+
\`\`\`
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
## More info:
|
|
495
|
+
|
|
496
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
497
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
498
|
+
- **Time:** ${new Date().toISOString()}
|
|
499
|
+
|
|
500
|
+
<details>
|
|
501
|
+
<summary>Stack trace:</summary>
|
|
502
|
+
|
|
503
|
+
## Stack trace:
|
|
504
|
+
|
|
505
|
+
\`\`\`stacktrace
|
|
506
|
+
${block(error.stack || '(empty)')}
|
|
507
|
+
\`\`\`
|
|
508
|
+
</details>
|
|
509
|
+
|
|
510
|
+
`),
|
|
511
|
+
};
|
|
512
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
513
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
514
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
515
|
+
reportUrl.searchParams.set('title', report.title);
|
|
516
|
+
reportUrl.searchParams.set('body', report.body);
|
|
517
|
+
return reportUrl;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
522
|
+
*
|
|
523
|
+
* @public exported from `@promptbook/core`
|
|
524
|
+
*/
|
|
525
|
+
class UnexpectedError extends Error {
|
|
526
|
+
constructor(message) {
|
|
527
|
+
super(spaceTrim$1((block) => `
|
|
528
|
+
${block(message)}
|
|
529
|
+
|
|
530
|
+
Note: This error should not happen.
|
|
531
|
+
It's probbably a bug in the pipeline collection
|
|
532
|
+
|
|
533
|
+
Please report issue:
|
|
534
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
535
|
+
|
|
536
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
537
|
+
|
|
538
|
+
`));
|
|
539
|
+
this.name = 'UnexpectedError';
|
|
540
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
546
|
+
*
|
|
547
|
+
* @public exported from `@promptbook/core`
|
|
548
|
+
*/
|
|
549
|
+
class WrappedError extends Error {
|
|
550
|
+
constructor(whatWasThrown) {
|
|
551
|
+
const tag = `[🤮]`;
|
|
552
|
+
console.error(tag, whatWasThrown);
|
|
553
|
+
super(spaceTrim$1(`
|
|
554
|
+
Non-Error object was thrown
|
|
555
|
+
|
|
556
|
+
Note: Look for ${tag} in the console for more details
|
|
557
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
558
|
+
`));
|
|
559
|
+
this.name = 'WrappedError';
|
|
560
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
566
|
+
*
|
|
567
|
+
* @param whatWasThrown Any object that was thrown
|
|
568
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
569
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
570
|
+
*
|
|
571
|
+
* @private within the repository
|
|
572
|
+
*/
|
|
573
|
+
function assertsError(whatWasThrown) {
|
|
574
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
575
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
576
|
+
const wrappedError = whatWasThrown;
|
|
577
|
+
throw wrappedError;
|
|
578
|
+
}
|
|
579
|
+
// Case 2: Handle unexpected errors
|
|
580
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
581
|
+
const unexpectedError = whatWasThrown;
|
|
582
|
+
throw unexpectedError;
|
|
583
|
+
}
|
|
584
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
585
|
+
if (whatWasThrown instanceof Error) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
589
|
+
throw new WrappedError(whatWasThrown);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
594
|
+
*
|
|
595
|
+
* @public exported from `@promptbook/utils`
|
|
596
|
+
*/
|
|
597
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
598
|
+
try {
|
|
599
|
+
JSON.parse(value);
|
|
600
|
+
return true;
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
assertsError(error);
|
|
604
|
+
if (error.message.includes('Unexpected token')) {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
613
|
+
* 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.
|
|
614
|
+
*
|
|
615
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
616
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
617
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
618
|
+
* @public exported from `@promptbook/core`
|
|
619
|
+
*/
|
|
620
|
+
function validatePipelineString(pipelineString) {
|
|
621
|
+
if (isValidJsonString(pipelineString)) {
|
|
622
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
623
|
+
}
|
|
624
|
+
else if (isValidUrl(pipelineString)) {
|
|
625
|
+
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
626
|
+
}
|
|
627
|
+
else if (isValidFilePath(pipelineString)) {
|
|
628
|
+
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
629
|
+
}
|
|
630
|
+
else if (isValidEmail(pipelineString)) {
|
|
631
|
+
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
632
|
+
}
|
|
633
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
634
|
+
return pipelineString;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
638
|
+
*/
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Prettify the html code
|
|
642
|
+
*
|
|
643
|
+
* @param content raw html code
|
|
644
|
+
* @returns formatted html code
|
|
645
|
+
* @private withing the package because of HUGE size of prettier dependency
|
|
646
|
+
*/
|
|
647
|
+
function prettifyMarkdown(content) {
|
|
648
|
+
try {
|
|
649
|
+
return format(content, {
|
|
650
|
+
parser: 'markdown',
|
|
651
|
+
plugins: [parserHtml],
|
|
652
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
653
|
+
endOfLine: 'lf',
|
|
654
|
+
tabWidth: 4,
|
|
655
|
+
singleQuote: true,
|
|
656
|
+
trailingComma: 'all',
|
|
657
|
+
arrowParens: 'always',
|
|
658
|
+
printWidth: 120,
|
|
659
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
660
|
+
jsxBracketSameLine: false,
|
|
661
|
+
bracketSpacing: true,
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
catch (error) {
|
|
665
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
666
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
667
|
+
error,
|
|
668
|
+
html: content,
|
|
669
|
+
});
|
|
670
|
+
return content;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Makes first letter of a string uppercase
|
|
676
|
+
*
|
|
677
|
+
* @public exported from `@promptbook/utils`
|
|
678
|
+
*/
|
|
679
|
+
function capitalize(word) {
|
|
680
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Converts promptbook in JSON format to string format
|
|
685
|
+
*
|
|
686
|
+
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
687
|
+
* @param pipelineJson Promptbook in JSON format (.bookc)
|
|
688
|
+
* @returns Promptbook in string format (.book.md)
|
|
689
|
+
* @public exported from `@promptbook/core`
|
|
690
|
+
*/
|
|
691
|
+
function pipelineJsonToString(pipelineJson) {
|
|
692
|
+
const { title, pipelineUrl, bookVersion, description, parameters, tasks } = pipelineJson;
|
|
693
|
+
let pipelineString = `# ${title}`;
|
|
694
|
+
if (description) {
|
|
695
|
+
pipelineString += '\n\n';
|
|
696
|
+
pipelineString += description;
|
|
697
|
+
}
|
|
698
|
+
const commands = [];
|
|
699
|
+
if (pipelineUrl) {
|
|
700
|
+
commands.push(`PIPELINE URL ${pipelineUrl}`);
|
|
701
|
+
}
|
|
702
|
+
if (bookVersion !== `undefined`) {
|
|
703
|
+
commands.push(`BOOK VERSION ${bookVersion}`);
|
|
704
|
+
}
|
|
705
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
706
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
707
|
+
for (const parameter of parameters.filter(({ isInput }) => isInput)) {
|
|
708
|
+
commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
709
|
+
}
|
|
710
|
+
for (const parameter of parameters.filter(({ isOutput }) => isOutput)) {
|
|
711
|
+
commands.push(`OUTPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
712
|
+
}
|
|
713
|
+
pipelineString += '\n\n';
|
|
714
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
715
|
+
for (const task of tasks) {
|
|
716
|
+
const {
|
|
717
|
+
/* Note: Not using:> name, */
|
|
718
|
+
title, description,
|
|
719
|
+
/* Note: dependentParameterNames, */
|
|
720
|
+
jokerParameterNames: jokers, taskType, content, postprocessingFunctionNames: postprocessing, expectations, format, resultingParameterName, } = task;
|
|
721
|
+
pipelineString += '\n\n';
|
|
722
|
+
pipelineString += `## ${title}`;
|
|
723
|
+
if (description) {
|
|
724
|
+
pipelineString += '\n\n';
|
|
725
|
+
pipelineString += description;
|
|
726
|
+
}
|
|
727
|
+
const commands = [];
|
|
728
|
+
let contentLanguage = 'text';
|
|
729
|
+
if (taskType === 'PROMPT_TASK') {
|
|
730
|
+
const { modelRequirements } = task;
|
|
731
|
+
const { modelName, modelVariant } = modelRequirements || {};
|
|
732
|
+
// Note: Do nothing, it is default
|
|
733
|
+
// commands.push(`PROMPT`);
|
|
734
|
+
if (modelVariant) {
|
|
735
|
+
commands.push(`MODEL VARIANT ${capitalize(modelVariant)}`);
|
|
736
|
+
}
|
|
737
|
+
if (modelName) {
|
|
738
|
+
commands.push(`MODEL NAME \`${modelName}\``);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
742
|
+
commands.push(`SIMPLE TEMPLATE`);
|
|
743
|
+
// Note: Nothing special here
|
|
744
|
+
}
|
|
745
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
746
|
+
commands.push(`SCRIPT`);
|
|
747
|
+
if (task.contentLanguage) {
|
|
748
|
+
contentLanguage = task.contentLanguage;
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
contentLanguage = '';
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
755
|
+
commands.push(`DIALOG`);
|
|
756
|
+
// Note: Nothing special here
|
|
757
|
+
} // <- }else if([🅱]
|
|
758
|
+
if (jokers) {
|
|
759
|
+
for (const joker of jokers) {
|
|
760
|
+
commands.push(`JOKER {${joker}}`);
|
|
761
|
+
}
|
|
762
|
+
} /* not else */
|
|
763
|
+
if (postprocessing) {
|
|
764
|
+
for (const postprocessingFunctionName of postprocessing) {
|
|
765
|
+
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
766
|
+
}
|
|
767
|
+
} /* not else */
|
|
768
|
+
if (expectations) {
|
|
769
|
+
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
770
|
+
if (min === max) {
|
|
771
|
+
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
if (min !== undefined) {
|
|
775
|
+
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
776
|
+
} /* not else */
|
|
777
|
+
if (max !== undefined) {
|
|
778
|
+
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
} /* not else */
|
|
783
|
+
if (format) {
|
|
784
|
+
if (format === 'JSON') {
|
|
785
|
+
// TODO: @deprecated remove
|
|
786
|
+
commands.push(`FORMAT JSON`);
|
|
787
|
+
}
|
|
788
|
+
} /* not else */
|
|
789
|
+
pipelineString += '\n\n';
|
|
790
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
791
|
+
pipelineString += '\n\n';
|
|
792
|
+
pipelineString += '```' + contentLanguage;
|
|
793
|
+
pipelineString += '\n';
|
|
794
|
+
pipelineString += spaceTrim(content);
|
|
795
|
+
// <- TODO: [main] !!3 Escape
|
|
796
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
797
|
+
pipelineString += '\n';
|
|
798
|
+
pipelineString += '```';
|
|
799
|
+
pipelineString += '\n\n';
|
|
800
|
+
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
801
|
+
}
|
|
802
|
+
return validatePipelineString(pipelineString);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* @private internal utility of `pipelineJsonToString`
|
|
670
806
|
*/
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
807
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
808
|
+
const { name, description } = taskParameterJson;
|
|
809
|
+
let parameterString = `{${name}}`;
|
|
810
|
+
if (description) {
|
|
811
|
+
parameterString = `${parameterString} ${description}`;
|
|
812
|
+
}
|
|
813
|
+
return parameterString;
|
|
814
|
+
}
|
|
675
815
|
/**
|
|
676
|
-
*
|
|
677
|
-
* TODO: [🧠]
|
|
816
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
817
|
+
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
818
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
819
|
+
* TODO: [🏛] Escape all
|
|
820
|
+
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
678
821
|
*/
|
|
679
822
|
|
|
680
823
|
/**
|
|
@@ -719,74 +862,6 @@ function $deepFreeze(objectValue) {
|
|
|
719
862
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
720
863
|
*/
|
|
721
864
|
|
|
722
|
-
/**
|
|
723
|
-
* Make error report URL for the given error
|
|
724
|
-
*
|
|
725
|
-
* @private private within the repository
|
|
726
|
-
*/
|
|
727
|
-
function getErrorReportUrl(error) {
|
|
728
|
-
const report = {
|
|
729
|
-
title: `🐜 Error report from ${NAME}`,
|
|
730
|
-
body: spaceTrim((block) => `
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
734
|
-
|
|
735
|
-
\`\`\`
|
|
736
|
-
${block(error.message || '(no error message)')}
|
|
737
|
-
\`\`\`
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
## More info:
|
|
741
|
-
|
|
742
|
-
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
743
|
-
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
744
|
-
- **Time:** ${new Date().toISOString()}
|
|
745
|
-
|
|
746
|
-
<details>
|
|
747
|
-
<summary>Stack trace:</summary>
|
|
748
|
-
|
|
749
|
-
## Stack trace:
|
|
750
|
-
|
|
751
|
-
\`\`\`stacktrace
|
|
752
|
-
${block(error.stack || '(empty)')}
|
|
753
|
-
\`\`\`
|
|
754
|
-
</details>
|
|
755
|
-
|
|
756
|
-
`),
|
|
757
|
-
};
|
|
758
|
-
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
759
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
760
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
761
|
-
reportUrl.searchParams.set('title', report.title);
|
|
762
|
-
reportUrl.searchParams.set('body', report.body);
|
|
763
|
-
return reportUrl;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
768
|
-
*
|
|
769
|
-
* @public exported from `@promptbook/core`
|
|
770
|
-
*/
|
|
771
|
-
class UnexpectedError extends Error {
|
|
772
|
-
constructor(message) {
|
|
773
|
-
super(spaceTrim$1((block) => `
|
|
774
|
-
${block(message)}
|
|
775
|
-
|
|
776
|
-
Note: This error should not happen.
|
|
777
|
-
It's probbably a bug in the pipeline collection
|
|
778
|
-
|
|
779
|
-
Please report issue:
|
|
780
|
-
${block(getErrorReportUrl(new Error(message)).href)}
|
|
781
|
-
|
|
782
|
-
Or contact us on ${ADMIN_EMAIL}
|
|
783
|
-
|
|
784
|
-
`));
|
|
785
|
-
this.name = 'UnexpectedError';
|
|
786
|
-
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
|
|
790
865
|
/**
|
|
791
866
|
* Checks if the value is [🚉] serializable as JSON
|
|
792
867
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -878,9 +953,7 @@ function checkSerializableAsJson(options) {
|
|
|
878
953
|
JSON.stringify(value); // <- TODO: [0]
|
|
879
954
|
}
|
|
880
955
|
catch (error) {
|
|
881
|
-
|
|
882
|
-
throw error;
|
|
883
|
-
}
|
|
956
|
+
assertsError(error);
|
|
884
957
|
throw new UnexpectedError(spaceTrim((block) => `
|
|
885
958
|
\`${name}\` is not serializable
|
|
886
959
|
|
|
@@ -1860,7 +1933,7 @@ class PipelineExecutionError extends Error {
|
|
|
1860
1933
|
}
|
|
1861
1934
|
}
|
|
1862
1935
|
/**
|
|
1863
|
-
* TODO:
|
|
1936
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
1864
1937
|
*/
|
|
1865
1938
|
|
|
1866
1939
|
/**
|
|
@@ -1893,6 +1966,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
1893
1966
|
}
|
|
1894
1967
|
}
|
|
1895
1968
|
|
|
1969
|
+
/**
|
|
1970
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1971
|
+
*
|
|
1972
|
+
* @public exported from `@promptbook/core`
|
|
1973
|
+
*/
|
|
1974
|
+
class AuthenticationError extends Error {
|
|
1975
|
+
constructor(message) {
|
|
1976
|
+
super(message);
|
|
1977
|
+
this.name = 'AuthenticationError';
|
|
1978
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1896
1982
|
/**
|
|
1897
1983
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1898
1984
|
*
|
|
@@ -1984,6 +2070,19 @@ class NotYetImplementedError extends Error {
|
|
|
1984
2070
|
}
|
|
1985
2071
|
}
|
|
1986
2072
|
|
|
2073
|
+
/**
|
|
2074
|
+
* Error thrown when a fetch request fails
|
|
2075
|
+
*
|
|
2076
|
+
* @public exported from `@promptbook/core`
|
|
2077
|
+
*/
|
|
2078
|
+
class PromptbookFetchError extends Error {
|
|
2079
|
+
constructor(message) {
|
|
2080
|
+
super(message);
|
|
2081
|
+
this.name = 'PromptbookFetchError';
|
|
2082
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
|
|
1987
2086
|
/**
|
|
1988
2087
|
* Index of all custom errors
|
|
1989
2088
|
*
|
|
@@ -2004,7 +2103,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2004
2103
|
PipelineExecutionError,
|
|
2005
2104
|
PipelineLogicError,
|
|
2006
2105
|
PipelineUrlError,
|
|
2106
|
+
AuthenticationError,
|
|
2107
|
+
PromptbookFetchError,
|
|
2007
2108
|
UnexpectedError,
|
|
2109
|
+
WrappedError,
|
|
2008
2110
|
// TODO: [🪑]> VersionMismatchError,
|
|
2009
2111
|
};
|
|
2010
2112
|
/**
|
|
@@ -2143,8 +2245,8 @@ function createTask(options) {
|
|
|
2143
2245
|
updatedAt = new Date();
|
|
2144
2246
|
errors.push(...executionResult.errors);
|
|
2145
2247
|
warnings.push(...executionResult.warnings);
|
|
2146
|
-
// <- TODO:
|
|
2147
|
-
// TODO: [🧠]
|
|
2248
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2249
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2148
2250
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2149
2251
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2150
2252
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2154,6 +2256,7 @@ function createTask(options) {
|
|
|
2154
2256
|
partialResultSubject.next(executionResult);
|
|
2155
2257
|
}
|
|
2156
2258
|
catch (error) {
|
|
2259
|
+
assertsError(error);
|
|
2157
2260
|
status = 'ERROR';
|
|
2158
2261
|
errors.push(error);
|
|
2159
2262
|
partialResultSubject.error(error);
|
|
@@ -2220,6 +2323,10 @@ function serializeError(error) {
|
|
|
2220
2323
|
|
|
2221
2324
|
Cannot serialize error with name "${name}"
|
|
2222
2325
|
|
|
2326
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2327
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2328
|
+
|
|
2329
|
+
|
|
2223
2330
|
${block(stack || message)}
|
|
2224
2331
|
|
|
2225
2332
|
`));
|
|
@@ -2295,13 +2402,19 @@ function valueToString(value) {
|
|
|
2295
2402
|
return value.toISOString();
|
|
2296
2403
|
}
|
|
2297
2404
|
else {
|
|
2298
|
-
|
|
2405
|
+
try {
|
|
2406
|
+
return JSON.stringify(value);
|
|
2407
|
+
}
|
|
2408
|
+
catch (error) {
|
|
2409
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2410
|
+
return VALUE_STRINGS.circular;
|
|
2411
|
+
}
|
|
2412
|
+
throw error;
|
|
2413
|
+
}
|
|
2299
2414
|
}
|
|
2300
2415
|
}
|
|
2301
2416
|
catch (error) {
|
|
2302
|
-
|
|
2303
|
-
throw error;
|
|
2304
|
-
}
|
|
2417
|
+
assertsError(error);
|
|
2305
2418
|
console.error(error);
|
|
2306
2419
|
return VALUE_STRINGS.unserializable;
|
|
2307
2420
|
}
|
|
@@ -2473,9 +2586,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
2473
2586
|
}
|
|
2474
2587
|
}
|
|
2475
2588
|
catch (error) {
|
|
2476
|
-
|
|
2477
|
-
throw error;
|
|
2478
|
-
}
|
|
2589
|
+
assertsError(error);
|
|
2479
2590
|
throw new ParseError(spaceTrim$1((block) => `
|
|
2480
2591
|
Can not extract variables from the script
|
|
2481
2592
|
${block(error.stack || error.message)}
|
|
@@ -2964,14 +3075,15 @@ class MultipleLlmExecutionTools {
|
|
|
2964
3075
|
}
|
|
2965
3076
|
}
|
|
2966
3077
|
catch (error) {
|
|
2967
|
-
|
|
3078
|
+
assertsError(error);
|
|
3079
|
+
if (error instanceof UnexpectedError) {
|
|
2968
3080
|
throw error;
|
|
2969
3081
|
}
|
|
2970
3082
|
errors.push({ llmExecutionTools, error });
|
|
2971
3083
|
}
|
|
2972
3084
|
}
|
|
2973
3085
|
if (errors.length === 1) {
|
|
2974
|
-
throw errors[0];
|
|
3086
|
+
throw errors[0].error;
|
|
2975
3087
|
}
|
|
2976
3088
|
else if (errors.length > 1) {
|
|
2977
3089
|
throw new PipelineExecutionError(
|
|
@@ -3850,9 +3962,7 @@ async function executeAttempts(options) {
|
|
|
3850
3962
|
break scripts;
|
|
3851
3963
|
}
|
|
3852
3964
|
catch (error) {
|
|
3853
|
-
|
|
3854
|
-
throw error;
|
|
3855
|
-
}
|
|
3965
|
+
assertsError(error);
|
|
3856
3966
|
if (error instanceof UnexpectedError) {
|
|
3857
3967
|
throw error;
|
|
3858
3968
|
}
|
|
@@ -3922,9 +4032,7 @@ async function executeAttempts(options) {
|
|
|
3922
4032
|
break scripts;
|
|
3923
4033
|
}
|
|
3924
4034
|
catch (error) {
|
|
3925
|
-
|
|
3926
|
-
throw error;
|
|
3927
|
-
}
|
|
4035
|
+
assertsError(error);
|
|
3928
4036
|
if (error instanceof UnexpectedError) {
|
|
3929
4037
|
throw error;
|
|
3930
4038
|
}
|
|
@@ -4545,9 +4653,7 @@ async function executePipeline(options) {
|
|
|
4545
4653
|
await Promise.all(resolving);
|
|
4546
4654
|
}
|
|
4547
4655
|
catch (error /* <- Note: [3] */) {
|
|
4548
|
-
|
|
4549
|
-
throw error;
|
|
4550
|
-
}
|
|
4656
|
+
assertsError(error);
|
|
4551
4657
|
// Note: No need to rethrow UnexpectedError
|
|
4552
4658
|
// if (error instanceof UnexpectedError) {
|
|
4553
4659
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5256,17 +5362,22 @@ function titleToName(value) {
|
|
|
5256
5362
|
/**
|
|
5257
5363
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5258
5364
|
*
|
|
5259
|
-
* @
|
|
5365
|
+
* @public exported from `@promptbook/core`
|
|
5260
5366
|
*/
|
|
5261
|
-
const
|
|
5367
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5262
5368
|
try {
|
|
5263
|
-
return await fetch(
|
|
5369
|
+
return await fetch(urlOrRequest, init);
|
|
5264
5370
|
}
|
|
5265
5371
|
catch (error) {
|
|
5266
|
-
|
|
5267
|
-
|
|
5372
|
+
assertsError(error);
|
|
5373
|
+
let url;
|
|
5374
|
+
if (typeof urlOrRequest === 'string') {
|
|
5375
|
+
url = urlOrRequest;
|
|
5376
|
+
}
|
|
5377
|
+
else if (urlOrRequest instanceof Request) {
|
|
5378
|
+
url = urlOrRequest.url;
|
|
5268
5379
|
}
|
|
5269
|
-
throw new
|
|
5380
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
5270
5381
|
Can not fetch "${url}"
|
|
5271
5382
|
|
|
5272
5383
|
Fetch error:
|
|
@@ -5287,7 +5398,7 @@ const scraperFetch = async (url, init) => {
|
|
|
5287
5398
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5288
5399
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5289
5400
|
var _a;
|
|
5290
|
-
const { fetch =
|
|
5401
|
+
const { fetch = promptbookFetch } = tools;
|
|
5291
5402
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5292
5403
|
let { name } = knowledgeSource;
|
|
5293
5404
|
const { rootDirname = null,
|
|
@@ -5489,9 +5600,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5489
5600
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5490
5601
|
}
|
|
5491
5602
|
catch (error) {
|
|
5492
|
-
|
|
5493
|
-
throw error;
|
|
5494
|
-
}
|
|
5603
|
+
assertsError(error);
|
|
5495
5604
|
console.warn(error);
|
|
5496
5605
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5497
5606
|
}
|
|
@@ -6289,6 +6398,8 @@ function parseNumber(value) {
|
|
|
6289
6398
|
*/
|
|
6290
6399
|
|
|
6291
6400
|
/**
|
|
6401
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6402
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6292
6403
|
* Parses the expect command
|
|
6293
6404
|
*
|
|
6294
6405
|
* @see `documentationUrl` for more details
|
|
@@ -6380,9 +6491,7 @@ const expectCommandParser = {
|
|
|
6380
6491
|
};
|
|
6381
6492
|
}
|
|
6382
6493
|
catch (error) {
|
|
6383
|
-
|
|
6384
|
-
throw error;
|
|
6385
|
-
}
|
|
6494
|
+
assertsError(error);
|
|
6386
6495
|
throw new ParseError(spaceTrim((block) => `
|
|
6387
6496
|
Invalid FORMAT command
|
|
6388
6497
|
${block(error.message)}:
|
|
@@ -10167,8 +10276,7 @@ const _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register(
|
|
|
10167
10276
|
options: {
|
|
10168
10277
|
apiKey: 'sk-ant-api03-',
|
|
10169
10278
|
isProxied: true,
|
|
10170
|
-
|
|
10171
|
-
path: DEFAULT_REMOTE_URL_PATH,
|
|
10279
|
+
remoteServerUrl: DEFAULT_REMOTE_SERVER_URL,
|
|
10172
10280
|
},
|
|
10173
10281
|
};
|
|
10174
10282
|
},
|
|
@@ -10477,9 +10585,7 @@ function isValidPipelineString(pipelineString) {
|
|
|
10477
10585
|
return true;
|
|
10478
10586
|
}
|
|
10479
10587
|
catch (error) {
|
|
10480
|
-
|
|
10481
|
-
throw error;
|
|
10482
|
-
}
|
|
10588
|
+
assertsError(error);
|
|
10483
10589
|
return false;
|
|
10484
10590
|
}
|
|
10485
10591
|
}
|
|
@@ -10574,6 +10680,40 @@ function book(strings, ...values) {
|
|
|
10574
10680
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10575
10681
|
*/
|
|
10576
10682
|
|
|
10683
|
+
/**
|
|
10684
|
+
* Convert identification to Promptbook token
|
|
10685
|
+
*
|
|
10686
|
+
* @param identification
|
|
10687
|
+
*
|
|
10688
|
+
* @public exported from `@promptbook/core`
|
|
10689
|
+
*/
|
|
10690
|
+
function identificationToPromptbookToken(identification) {
|
|
10691
|
+
const { appId, userId, userToken } = identification;
|
|
10692
|
+
const promptbookToken = `${appId}-${userId}-${userToken}`;
|
|
10693
|
+
return promptbookToken;
|
|
10694
|
+
}
|
|
10695
|
+
|
|
10696
|
+
/**
|
|
10697
|
+
* Convert Promptbook token to identification
|
|
10698
|
+
*
|
|
10699
|
+
* @param promptbookToken
|
|
10700
|
+
*
|
|
10701
|
+
* @public exported from `@promptbook/core`
|
|
10702
|
+
*/
|
|
10703
|
+
function promptbookTokenToIdentification(promptbookToken) {
|
|
10704
|
+
const [appId, userId, userToken] = promptbookToken.split('-');
|
|
10705
|
+
if (!appId || !userId || !userToken) {
|
|
10706
|
+
throw new Error(`Invalid promptbook token: ${promptbookToken}`);
|
|
10707
|
+
}
|
|
10708
|
+
const identification = {
|
|
10709
|
+
appId,
|
|
10710
|
+
userId,
|
|
10711
|
+
userToken,
|
|
10712
|
+
isAnonymous: false,
|
|
10713
|
+
};
|
|
10714
|
+
return identification;
|
|
10715
|
+
}
|
|
10716
|
+
|
|
10577
10717
|
/**
|
|
10578
10718
|
* Metadata of the scraper
|
|
10579
10719
|
*
|
|
@@ -10863,5 +11003,5 @@ class PrefixStorage {
|
|
|
10863
11003
|
}
|
|
10864
11004
|
}
|
|
10865
11005
|
|
|
10866
|
-
export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE,
|
|
11006
|
+
export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, AbstractFormatError, AuthenticationError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_TITLE, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, PLAYGROUND_APP_ID, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, REMOTE_SERVER_URLS, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, book, cacheLlmTools, collectionToJson, compilePipeline, countUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, getPipelineInterface, identificationToPromptbookToken, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, parsePipeline, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline, validatePipelineString };
|
|
10867
11007
|
//# sourceMappingURL=index.es.js.map
|