@promptbook/core 0.89.0-9 โ 0.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -11
- package/esm/index.es.js +514 -376
- 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 +8 -4
- package/esm/typings/src/_packages/types.index.d.ts +18 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
- 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 +10 -19
- package/esm/typings/src/errors/0-index.d.ts +7 -4
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- 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/formats/csv/utils/isValidCsvString.d.ts +9 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts โ $provideEnvFilename.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- 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/Identification.d.ts +7 -1
- 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/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +26 -0
- package/package.json +7 -3
- package/umd/index.umd.js +517 -377
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
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';
|
|
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,34 @@ 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.
|
|
162
|
+
* Available remote servers for the Promptbook
|
|
185
163
|
*
|
|
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
164
|
* @public exported from `@promptbook/core`
|
|
190
165
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
|
256
|
-
*
|
|
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
|
-
* @public exported from `@promptbook/core`
|
|
261
|
-
*/
|
|
262
|
-
function pipelineJsonToString(pipelineJson) {
|
|
263
|
-
const { title, pipelineUrl, bookVersion, description, parameters, tasks } = pipelineJson;
|
|
264
|
-
let pipelineString = `# ${title}`;
|
|
265
|
-
if (description) {
|
|
266
|
-
pipelineString += '\n\n';
|
|
267
|
-
pipelineString += description;
|
|
268
|
-
}
|
|
269
|
-
const commands = [];
|
|
270
|
-
if (pipelineUrl) {
|
|
271
|
-
commands.push(`PIPELINE URL ${pipelineUrl}`);
|
|
272
|
-
}
|
|
273
|
-
if (bookVersion !== `undefined`) {
|
|
274
|
-
commands.push(`BOOK VERSION ${bookVersion}`);
|
|
275
|
-
}
|
|
276
|
-
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
277
|
-
pipelineString = prettifyMarkdown(pipelineString);
|
|
278
|
-
for (const parameter of parameters.filter(({ isInput }) => isInput)) {
|
|
279
|
-
commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
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://promptbook.s5.ptbk.io/',
|
|
174
|
+
// Note: Servers 1-4 are not running
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
/*
|
|
178
|
+
Note: Working on older version of Promptbook and not supported anymore
|
|
179
|
+
{
|
|
180
|
+
title: 'Pavol Promptbook Server',
|
|
181
|
+
description: `Personal server of Pavol Hejnรฝ with simple testing server, DO NOT USE IT FOR PRODUCTION`,
|
|
182
|
+
owner: 'Pavol Hejnรฝ <pavol@ptbk.io> (https://www.pavolhejny.com/)',
|
|
183
|
+
isAnonymousModeAllowed: true,
|
|
184
|
+
urls: ['https://api.pavolhejny.com/promptbook'],
|
|
185
|
+
},
|
|
186
|
+
*/
|
|
187
|
+
];
|
|
386
188
|
/**
|
|
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
|
|
189
|
+
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
392
190
|
*/
|
|
393
191
|
|
|
394
192
|
/**
|
|
@@ -446,22 +244,6 @@ const ADMIN_GITHUB_NAME = 'hejny';
|
|
|
446
244
|
*/
|
|
447
245
|
const CLAIM = `It's time for a paradigm shift. The future of software in plain English, French or Latin`;
|
|
448
246
|
// <- 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
247
|
/**
|
|
466
248
|
* When the title is not provided, the default title is used
|
|
467
249
|
*
|
|
@@ -512,6 +294,7 @@ const VALUE_STRINGS = {
|
|
|
512
294
|
infinity: '(infinity; โ)',
|
|
513
295
|
negativeInfinity: '(negative infinity; -โ)',
|
|
514
296
|
unserializable: '(unserializable value)',
|
|
297
|
+
circular: '(circular JSON)',
|
|
515
298
|
};
|
|
516
299
|
/**
|
|
517
300
|
* Small number limit
|
|
@@ -572,7 +355,7 @@ const DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
|
|
|
572
355
|
*/
|
|
573
356
|
const DEFAULT_BOOKS_DIRNAME = './books';
|
|
574
357
|
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
575
|
-
// TODO:
|
|
358
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
576
359
|
/**
|
|
577
360
|
* Where to store the temporary downloads
|
|
578
361
|
*
|
|
@@ -634,11 +417,11 @@ const MOMENT_ARG_THRESHOLDS = {
|
|
|
634
417
|
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.
|
|
635
418
|
};
|
|
636
419
|
/**
|
|
637
|
-
*
|
|
420
|
+
* Default remote server URL for the Promptbook
|
|
638
421
|
*
|
|
639
422
|
* @public exported from `@promptbook/core`
|
|
640
423
|
*/
|
|
641
|
-
const DEFAULT_REMOTE_SERVER_URL =
|
|
424
|
+
const DEFAULT_REMOTE_SERVER_URL = REMOTE_SERVER_URLS[0].urls[0];
|
|
642
425
|
// <- TODO: [๐งโโ๏ธ]
|
|
643
426
|
/**
|
|
644
427
|
* @@@
|
|
@@ -668,29 +451,379 @@ function SET_IS_VERBOSE(isVerbose) {
|
|
|
668
451
|
DEFAULT_IS_VERBOSE = isVerbose;
|
|
669
452
|
}
|
|
670
453
|
/**
|
|
671
|
-
* @@@
|
|
672
|
-
*
|
|
673
|
-
* @public exported from `@promptbook/core`
|
|
674
|
-
*/
|
|
675
|
-
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
676
|
-
/**
|
|
677
|
-
* Function name for generated function via `ptbk make` to get the pipeline collection
|
|
678
|
-
*
|
|
679
|
-
* @public exported from `@promptbook/core`
|
|
680
|
-
*/
|
|
681
|
-
const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = `getPipelineCollection`;
|
|
682
|
-
/**
|
|
683
|
-
* @@@
|
|
684
|
-
*
|
|
685
|
-
* @private within the repository
|
|
454
|
+
* @@@
|
|
455
|
+
*
|
|
456
|
+
* @public exported from `@promptbook/core`
|
|
457
|
+
*/
|
|
458
|
+
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
459
|
+
/**
|
|
460
|
+
* Function name for generated function via `ptbk make` to get the pipeline collection
|
|
461
|
+
*
|
|
462
|
+
* @public exported from `@promptbook/core`
|
|
463
|
+
*/
|
|
464
|
+
const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = `getPipelineCollection`;
|
|
465
|
+
/**
|
|
466
|
+
* @@@
|
|
467
|
+
*
|
|
468
|
+
* @private within the repository
|
|
469
|
+
*/
|
|
470
|
+
const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
471
|
+
/**/
|
|
472
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
473
|
+
true);
|
|
474
|
+
/**
|
|
475
|
+
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
476
|
+
* TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteServerUrl and path into single value
|
|
477
|
+
*/
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Make error report URL for the given error
|
|
481
|
+
*
|
|
482
|
+
* @private private within the repository
|
|
483
|
+
*/
|
|
484
|
+
function getErrorReportUrl(error) {
|
|
485
|
+
const report = {
|
|
486
|
+
title: `๐ Error report from ${NAME}`,
|
|
487
|
+
body: spaceTrim((block) => `
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
491
|
+
|
|
492
|
+
\`\`\`
|
|
493
|
+
${block(error.message || '(no error message)')}
|
|
494
|
+
\`\`\`
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
## More info:
|
|
498
|
+
|
|
499
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
500
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
501
|
+
- **Time:** ${new Date().toISOString()}
|
|
502
|
+
|
|
503
|
+
<details>
|
|
504
|
+
<summary>Stack trace:</summary>
|
|
505
|
+
|
|
506
|
+
## Stack trace:
|
|
507
|
+
|
|
508
|
+
\`\`\`stacktrace
|
|
509
|
+
${block(error.stack || '(empty)')}
|
|
510
|
+
\`\`\`
|
|
511
|
+
</details>
|
|
512
|
+
|
|
513
|
+
`),
|
|
514
|
+
};
|
|
515
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
516
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
517
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
518
|
+
reportUrl.searchParams.set('title', report.title);
|
|
519
|
+
reportUrl.searchParams.set('body', report.body);
|
|
520
|
+
return reportUrl;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
525
|
+
*
|
|
526
|
+
* @public exported from `@promptbook/core`
|
|
527
|
+
*/
|
|
528
|
+
class UnexpectedError extends Error {
|
|
529
|
+
constructor(message) {
|
|
530
|
+
super(spaceTrim$1((block) => `
|
|
531
|
+
${block(message)}
|
|
532
|
+
|
|
533
|
+
Note: This error should not happen.
|
|
534
|
+
It's probbably a bug in the pipeline collection
|
|
535
|
+
|
|
536
|
+
Please report issue:
|
|
537
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
538
|
+
|
|
539
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
540
|
+
|
|
541
|
+
`));
|
|
542
|
+
this.name = 'UnexpectedError';
|
|
543
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
549
|
+
*
|
|
550
|
+
* @public exported from `@promptbook/core`
|
|
551
|
+
*/
|
|
552
|
+
class WrappedError extends Error {
|
|
553
|
+
constructor(whatWasThrown) {
|
|
554
|
+
const tag = `[๐คฎ]`;
|
|
555
|
+
console.error(tag, whatWasThrown);
|
|
556
|
+
super(spaceTrim$1(`
|
|
557
|
+
Non-Error object was thrown
|
|
558
|
+
|
|
559
|
+
Note: Look for ${tag} in the console for more details
|
|
560
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
561
|
+
`));
|
|
562
|
+
this.name = 'WrappedError';
|
|
563
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
569
|
+
*
|
|
570
|
+
* @param whatWasThrown Any object that was thrown
|
|
571
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
572
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
573
|
+
*
|
|
574
|
+
* @private within the repository
|
|
575
|
+
*/
|
|
576
|
+
function assertsError(whatWasThrown) {
|
|
577
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
578
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
579
|
+
const wrappedError = whatWasThrown;
|
|
580
|
+
throw wrappedError;
|
|
581
|
+
}
|
|
582
|
+
// Case 2: Handle unexpected errors
|
|
583
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
584
|
+
const unexpectedError = whatWasThrown;
|
|
585
|
+
throw unexpectedError;
|
|
586
|
+
}
|
|
587
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
588
|
+
if (whatWasThrown instanceof Error) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
592
|
+
throw new WrappedError(whatWasThrown);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
597
|
+
*
|
|
598
|
+
* @param value The string to check
|
|
599
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
600
|
+
*
|
|
601
|
+
* @public exported from `@promptbook/utils`
|
|
602
|
+
*/
|
|
603
|
+
function isValidJsonString(value /* <- [๐จโโ๏ธ] */) {
|
|
604
|
+
try {
|
|
605
|
+
JSON.parse(value);
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
assertsError(error);
|
|
610
|
+
if (error.message.includes('Unexpected token')) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
619
|
+
* 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.
|
|
620
|
+
*
|
|
621
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
622
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
623
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
624
|
+
* @public exported from `@promptbook/core`
|
|
625
|
+
*/
|
|
626
|
+
function validatePipelineString(pipelineString) {
|
|
627
|
+
if (isValidJsonString(pipelineString)) {
|
|
628
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
629
|
+
}
|
|
630
|
+
else if (isValidUrl(pipelineString)) {
|
|
631
|
+
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
632
|
+
}
|
|
633
|
+
else if (isValidFilePath(pipelineString)) {
|
|
634
|
+
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
635
|
+
}
|
|
636
|
+
else if (isValidEmail(pipelineString)) {
|
|
637
|
+
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
638
|
+
}
|
|
639
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
640
|
+
return pipelineString;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* TODO: [๐ง ][๐ด] Where is the best location for this file
|
|
644
|
+
*/
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Prettify the html code
|
|
648
|
+
*
|
|
649
|
+
* @param content raw html code
|
|
650
|
+
* @returns formatted html code
|
|
651
|
+
* @private withing the package because of HUGE size of prettier dependency
|
|
652
|
+
*/
|
|
653
|
+
function prettifyMarkdown(content) {
|
|
654
|
+
try {
|
|
655
|
+
return format(content, {
|
|
656
|
+
parser: 'markdown',
|
|
657
|
+
plugins: [parserHtml],
|
|
658
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
659
|
+
endOfLine: 'lf',
|
|
660
|
+
tabWidth: 4,
|
|
661
|
+
singleQuote: true,
|
|
662
|
+
trailingComma: 'all',
|
|
663
|
+
arrowParens: 'always',
|
|
664
|
+
printWidth: 120,
|
|
665
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
666
|
+
jsxBracketSameLine: false,
|
|
667
|
+
bracketSpacing: true,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
catch (error) {
|
|
671
|
+
// TODO: [๐ฅ] Detect browser / node and make it colorfull
|
|
672
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
673
|
+
error,
|
|
674
|
+
html: content,
|
|
675
|
+
});
|
|
676
|
+
return content;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Makes first letter of a string uppercase
|
|
682
|
+
*
|
|
683
|
+
* @public exported from `@promptbook/utils`
|
|
684
|
+
*/
|
|
685
|
+
function capitalize(word) {
|
|
686
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Converts promptbook in JSON format to string format
|
|
691
|
+
*
|
|
692
|
+
* @deprecated TODO: [๐ฅ][๐ง ] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
693
|
+
* @param pipelineJson Promptbook in JSON format (.bookc)
|
|
694
|
+
* @returns Promptbook in string format (.book.md)
|
|
695
|
+
* @public exported from `@promptbook/core`
|
|
696
|
+
*/
|
|
697
|
+
function pipelineJsonToString(pipelineJson) {
|
|
698
|
+
const { title, pipelineUrl, bookVersion, description, parameters, tasks } = pipelineJson;
|
|
699
|
+
let pipelineString = `# ${title}`;
|
|
700
|
+
if (description) {
|
|
701
|
+
pipelineString += '\n\n';
|
|
702
|
+
pipelineString += description;
|
|
703
|
+
}
|
|
704
|
+
const commands = [];
|
|
705
|
+
if (pipelineUrl) {
|
|
706
|
+
commands.push(`PIPELINE URL ${pipelineUrl}`);
|
|
707
|
+
}
|
|
708
|
+
if (bookVersion !== `undefined`) {
|
|
709
|
+
commands.push(`BOOK VERSION ${bookVersion}`);
|
|
710
|
+
}
|
|
711
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
712
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
713
|
+
for (const parameter of parameters.filter(({ isInput }) => isInput)) {
|
|
714
|
+
commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
715
|
+
}
|
|
716
|
+
for (const parameter of parameters.filter(({ isOutput }) => isOutput)) {
|
|
717
|
+
commands.push(`OUTPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
718
|
+
}
|
|
719
|
+
pipelineString += '\n\n';
|
|
720
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
721
|
+
for (const task of tasks) {
|
|
722
|
+
const {
|
|
723
|
+
/* Note: Not using:> name, */
|
|
724
|
+
title, description,
|
|
725
|
+
/* Note: dependentParameterNames, */
|
|
726
|
+
jokerParameterNames: jokers, taskType, content, postprocessingFunctionNames: postprocessing, expectations, format, resultingParameterName, } = task;
|
|
727
|
+
pipelineString += '\n\n';
|
|
728
|
+
pipelineString += `## ${title}`;
|
|
729
|
+
if (description) {
|
|
730
|
+
pipelineString += '\n\n';
|
|
731
|
+
pipelineString += description;
|
|
732
|
+
}
|
|
733
|
+
const commands = [];
|
|
734
|
+
let contentLanguage = 'text';
|
|
735
|
+
if (taskType === 'PROMPT_TASK') {
|
|
736
|
+
const { modelRequirements } = task;
|
|
737
|
+
const { modelName, modelVariant } = modelRequirements || {};
|
|
738
|
+
// Note: Do nothing, it is default
|
|
739
|
+
// commands.push(`PROMPT`);
|
|
740
|
+
if (modelVariant) {
|
|
741
|
+
commands.push(`MODEL VARIANT ${capitalize(modelVariant)}`);
|
|
742
|
+
}
|
|
743
|
+
if (modelName) {
|
|
744
|
+
commands.push(`MODEL NAME \`${modelName}\``);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
748
|
+
commands.push(`SIMPLE TEMPLATE`);
|
|
749
|
+
// Note: Nothing special here
|
|
750
|
+
}
|
|
751
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
752
|
+
commands.push(`SCRIPT`);
|
|
753
|
+
if (task.contentLanguage) {
|
|
754
|
+
contentLanguage = task.contentLanguage;
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
contentLanguage = '';
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
761
|
+
commands.push(`DIALOG`);
|
|
762
|
+
// Note: Nothing special here
|
|
763
|
+
} // <- }else if([๐
ฑ]
|
|
764
|
+
if (jokers) {
|
|
765
|
+
for (const joker of jokers) {
|
|
766
|
+
commands.push(`JOKER {${joker}}`);
|
|
767
|
+
}
|
|
768
|
+
} /* not else */
|
|
769
|
+
if (postprocessing) {
|
|
770
|
+
for (const postprocessingFunctionName of postprocessing) {
|
|
771
|
+
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
772
|
+
}
|
|
773
|
+
} /* not else */
|
|
774
|
+
if (expectations) {
|
|
775
|
+
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
776
|
+
if (min === max) {
|
|
777
|
+
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
if (min !== undefined) {
|
|
781
|
+
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
782
|
+
} /* not else */
|
|
783
|
+
if (max !== undefined) {
|
|
784
|
+
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
} /* not else */
|
|
789
|
+
if (format) {
|
|
790
|
+
if (format === 'JSON') {
|
|
791
|
+
// TODO: @deprecated remove
|
|
792
|
+
commands.push(`FORMAT JSON`);
|
|
793
|
+
}
|
|
794
|
+
} /* not else */
|
|
795
|
+
pipelineString += '\n\n';
|
|
796
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
797
|
+
pipelineString += '\n\n';
|
|
798
|
+
pipelineString += '```' + contentLanguage;
|
|
799
|
+
pipelineString += '\n';
|
|
800
|
+
pipelineString += spaceTrim(content);
|
|
801
|
+
// <- TODO: [main] !!3 Escape
|
|
802
|
+
// <- TODO: [๐ง ] Some clear strategy how to spaceTrim the blocks
|
|
803
|
+
pipelineString += '\n';
|
|
804
|
+
pipelineString += '```';
|
|
805
|
+
pipelineString += '\n\n';
|
|
806
|
+
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
807
|
+
}
|
|
808
|
+
return validatePipelineString(pipelineString);
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* @private internal utility of `pipelineJsonToString`
|
|
686
812
|
*/
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
813
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
814
|
+
const { name, description } = taskParameterJson;
|
|
815
|
+
let parameterString = `{${name}}`;
|
|
816
|
+
if (description) {
|
|
817
|
+
parameterString = `${parameterString} ${description}`;
|
|
818
|
+
}
|
|
819
|
+
return parameterString;
|
|
820
|
+
}
|
|
691
821
|
/**
|
|
692
|
-
*
|
|
693
|
-
* TODO: [๐ง ]
|
|
822
|
+
* TODO: [๐] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
823
|
+
* TODO: [๐ง ] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
824
|
+
* TODO: [๐] Maybe make some markdown builder
|
|
825
|
+
* TODO: [๐] Escape all
|
|
826
|
+
* TODO: [๐ง ] Should be in generated .book.md file GENERATOR_WARNING
|
|
694
827
|
*/
|
|
695
828
|
|
|
696
829
|
/**
|
|
@@ -735,74 +868,6 @@ function $deepFreeze(objectValue) {
|
|
|
735
868
|
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
736
869
|
*/
|
|
737
870
|
|
|
738
|
-
/**
|
|
739
|
-
* Make error report URL for the given error
|
|
740
|
-
*
|
|
741
|
-
* @private private within the repository
|
|
742
|
-
*/
|
|
743
|
-
function getErrorReportUrl(error) {
|
|
744
|
-
const report = {
|
|
745
|
-
title: `๐ Error report from ${NAME}`,
|
|
746
|
-
body: spaceTrim((block) => `
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
750
|
-
|
|
751
|
-
\`\`\`
|
|
752
|
-
${block(error.message || '(no error message)')}
|
|
753
|
-
\`\`\`
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
## More info:
|
|
757
|
-
|
|
758
|
-
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
759
|
-
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
760
|
-
- **Time:** ${new Date().toISOString()}
|
|
761
|
-
|
|
762
|
-
<details>
|
|
763
|
-
<summary>Stack trace:</summary>
|
|
764
|
-
|
|
765
|
-
## Stack trace:
|
|
766
|
-
|
|
767
|
-
\`\`\`stacktrace
|
|
768
|
-
${block(error.stack || '(empty)')}
|
|
769
|
-
\`\`\`
|
|
770
|
-
</details>
|
|
771
|
-
|
|
772
|
-
`),
|
|
773
|
-
};
|
|
774
|
-
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
775
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
776
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
777
|
-
reportUrl.searchParams.set('title', report.title);
|
|
778
|
-
reportUrl.searchParams.set('body', report.body);
|
|
779
|
-
return reportUrl;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
784
|
-
*
|
|
785
|
-
* @public exported from `@promptbook/core`
|
|
786
|
-
*/
|
|
787
|
-
class UnexpectedError extends Error {
|
|
788
|
-
constructor(message) {
|
|
789
|
-
super(spaceTrim$1((block) => `
|
|
790
|
-
${block(message)}
|
|
791
|
-
|
|
792
|
-
Note: This error should not happen.
|
|
793
|
-
It's probbably a bug in the pipeline collection
|
|
794
|
-
|
|
795
|
-
Please report issue:
|
|
796
|
-
${block(getErrorReportUrl(new Error(message)).href)}
|
|
797
|
-
|
|
798
|
-
Or contact us on ${ADMIN_EMAIL}
|
|
799
|
-
|
|
800
|
-
`));
|
|
801
|
-
this.name = 'UnexpectedError';
|
|
802
|
-
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
|
|
806
871
|
/**
|
|
807
872
|
* Checks if the value is [๐] serializable as JSON
|
|
808
873
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -894,9 +959,7 @@ function checkSerializableAsJson(options) {
|
|
|
894
959
|
JSON.stringify(value); // <- TODO: [0]
|
|
895
960
|
}
|
|
896
961
|
catch (error) {
|
|
897
|
-
|
|
898
|
-
throw error;
|
|
899
|
-
}
|
|
962
|
+
assertsError(error);
|
|
900
963
|
throw new UnexpectedError(spaceTrim((block) => `
|
|
901
964
|
\`${name}\` is not serializable
|
|
902
965
|
|
|
@@ -1876,7 +1939,7 @@ class PipelineExecutionError extends Error {
|
|
|
1876
1939
|
}
|
|
1877
1940
|
}
|
|
1878
1941
|
/**
|
|
1879
|
-
* TODO:
|
|
1942
|
+
* TODO: [๐ง ][๐] Add id to all errors
|
|
1880
1943
|
*/
|
|
1881
1944
|
|
|
1882
1945
|
/**
|
|
@@ -2046,7 +2109,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2046
2109
|
PipelineExecutionError,
|
|
2047
2110
|
PipelineLogicError,
|
|
2048
2111
|
PipelineUrlError,
|
|
2112
|
+
AuthenticationError,
|
|
2113
|
+
PromptbookFetchError,
|
|
2049
2114
|
UnexpectedError,
|
|
2115
|
+
WrappedError,
|
|
2050
2116
|
// TODO: [๐ช]> VersionMismatchError,
|
|
2051
2117
|
};
|
|
2052
2118
|
/**
|
|
@@ -2063,8 +2129,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
2063
2129
|
TypeError,
|
|
2064
2130
|
URIError,
|
|
2065
2131
|
AggregateError,
|
|
2066
|
-
AuthenticationError,
|
|
2067
|
-
PromptbookFetchError,
|
|
2068
2132
|
/*
|
|
2069
2133
|
Note: Not widely supported
|
|
2070
2134
|
> InternalError,
|
|
@@ -2187,8 +2251,8 @@ function createTask(options) {
|
|
|
2187
2251
|
updatedAt = new Date();
|
|
2188
2252
|
errors.push(...executionResult.errors);
|
|
2189
2253
|
warnings.push(...executionResult.warnings);
|
|
2190
|
-
// <- TODO:
|
|
2191
|
-
// TODO: [๐ง ]
|
|
2254
|
+
// <- TODO: [๐] Only unique errors and warnings should be added (or filtered)
|
|
2255
|
+
// TODO: [๐ง ] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2192
2256
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2193
2257
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2194
2258
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2198,6 +2262,7 @@ function createTask(options) {
|
|
|
2198
2262
|
partialResultSubject.next(executionResult);
|
|
2199
2263
|
}
|
|
2200
2264
|
catch (error) {
|
|
2265
|
+
assertsError(error);
|
|
2201
2266
|
status = 'ERROR';
|
|
2202
2267
|
errors.push(error);
|
|
2203
2268
|
partialResultSubject.error(error);
|
|
@@ -2343,13 +2408,19 @@ function valueToString(value) {
|
|
|
2343
2408
|
return value.toISOString();
|
|
2344
2409
|
}
|
|
2345
2410
|
else {
|
|
2346
|
-
|
|
2411
|
+
try {
|
|
2412
|
+
return JSON.stringify(value);
|
|
2413
|
+
}
|
|
2414
|
+
catch (error) {
|
|
2415
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2416
|
+
return VALUE_STRINGS.circular;
|
|
2417
|
+
}
|
|
2418
|
+
throw error;
|
|
2419
|
+
}
|
|
2347
2420
|
}
|
|
2348
2421
|
}
|
|
2349
2422
|
catch (error) {
|
|
2350
|
-
|
|
2351
|
-
throw error;
|
|
2352
|
-
}
|
|
2423
|
+
assertsError(error);
|
|
2353
2424
|
console.error(error);
|
|
2354
2425
|
return VALUE_STRINGS.unserializable;
|
|
2355
2426
|
}
|
|
@@ -2521,9 +2592,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
2521
2592
|
}
|
|
2522
2593
|
}
|
|
2523
2594
|
catch (error) {
|
|
2524
|
-
|
|
2525
|
-
throw error;
|
|
2526
|
-
}
|
|
2595
|
+
assertsError(error);
|
|
2527
2596
|
throw new ParseError(spaceTrim$1((block) => `
|
|
2528
2597
|
Can not extract variables from the script
|
|
2529
2598
|
${block(error.stack || error.message)}
|
|
@@ -2642,6 +2711,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
2642
2711
|
// encoding: 'utf-8',
|
|
2643
2712
|
});
|
|
2644
2713
|
|
|
2714
|
+
/**
|
|
2715
|
+
* Function to check if a string is valid CSV
|
|
2716
|
+
*
|
|
2717
|
+
* @param value The string to check
|
|
2718
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
2719
|
+
*
|
|
2720
|
+
* @public exported from `@promptbook/utils`
|
|
2721
|
+
*/
|
|
2722
|
+
function isValidCsvString(value) {
|
|
2723
|
+
try {
|
|
2724
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
2725
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
2726
|
+
return true;
|
|
2727
|
+
}
|
|
2728
|
+
return false;
|
|
2729
|
+
}
|
|
2730
|
+
catch (error) {
|
|
2731
|
+
assertsError(error);
|
|
2732
|
+
return false;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2645
2736
|
/**
|
|
2646
2737
|
* Definition for CSV spreadsheet
|
|
2647
2738
|
*
|
|
@@ -2652,7 +2743,7 @@ const CsvFormatDefinition = {
|
|
|
2652
2743
|
formatName: 'CSV',
|
|
2653
2744
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
2654
2745
|
isValid(value, settings, schema) {
|
|
2655
|
-
return
|
|
2746
|
+
return isValidCsvString(value);
|
|
2656
2747
|
},
|
|
2657
2748
|
canBeValid(partialValue, settings, schema) {
|
|
2658
2749
|
return true;
|
|
@@ -2806,6 +2897,30 @@ const TextFormatDefinition = {
|
|
|
2806
2897
|
* TODO: [๐ข] Allow to expect something inside each item of list and other formats
|
|
2807
2898
|
*/
|
|
2808
2899
|
|
|
2900
|
+
/**
|
|
2901
|
+
* Function to check if a string is valid XML
|
|
2902
|
+
*
|
|
2903
|
+
* @param value
|
|
2904
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
2905
|
+
*
|
|
2906
|
+
* @public exported from `@promptbook/utils`
|
|
2907
|
+
*/
|
|
2908
|
+
function isValidXmlString(value) {
|
|
2909
|
+
try {
|
|
2910
|
+
const parser = new DOMParser();
|
|
2911
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
2912
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
2913
|
+
if (parserError.length > 0) {
|
|
2914
|
+
return false;
|
|
2915
|
+
}
|
|
2916
|
+
return true;
|
|
2917
|
+
}
|
|
2918
|
+
catch (error) {
|
|
2919
|
+
assertsError(error);
|
|
2920
|
+
return false;
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2809
2924
|
/**
|
|
2810
2925
|
* Definition for XML format
|
|
2811
2926
|
*
|
|
@@ -2815,7 +2930,7 @@ const XmlFormatDefinition = {
|
|
|
2815
2930
|
formatName: 'XML',
|
|
2816
2931
|
mimeType: 'application/xml',
|
|
2817
2932
|
isValid(value, settings, schema) {
|
|
2818
|
-
return
|
|
2933
|
+
return isValidXmlString(value);
|
|
2819
2934
|
},
|
|
2820
2935
|
canBeValid(partialValue, settings, schema) {
|
|
2821
2936
|
return true;
|
|
@@ -3012,14 +3127,15 @@ class MultipleLlmExecutionTools {
|
|
|
3012
3127
|
}
|
|
3013
3128
|
}
|
|
3014
3129
|
catch (error) {
|
|
3015
|
-
|
|
3130
|
+
assertsError(error);
|
|
3131
|
+
if (error instanceof UnexpectedError) {
|
|
3016
3132
|
throw error;
|
|
3017
3133
|
}
|
|
3018
3134
|
errors.push({ llmExecutionTools, error });
|
|
3019
3135
|
}
|
|
3020
3136
|
}
|
|
3021
3137
|
if (errors.length === 1) {
|
|
3022
|
-
throw errors[0];
|
|
3138
|
+
throw errors[0].error;
|
|
3023
3139
|
}
|
|
3024
3140
|
else if (errors.length > 1) {
|
|
3025
3141
|
throw new PipelineExecutionError(
|
|
@@ -3898,9 +4014,7 @@ async function executeAttempts(options) {
|
|
|
3898
4014
|
break scripts;
|
|
3899
4015
|
}
|
|
3900
4016
|
catch (error) {
|
|
3901
|
-
|
|
3902
|
-
throw error;
|
|
3903
|
-
}
|
|
4017
|
+
assertsError(error);
|
|
3904
4018
|
if (error instanceof UnexpectedError) {
|
|
3905
4019
|
throw error;
|
|
3906
4020
|
}
|
|
@@ -3970,9 +4084,7 @@ async function executeAttempts(options) {
|
|
|
3970
4084
|
break scripts;
|
|
3971
4085
|
}
|
|
3972
4086
|
catch (error) {
|
|
3973
|
-
|
|
3974
|
-
throw error;
|
|
3975
|
-
}
|
|
4087
|
+
assertsError(error);
|
|
3976
4088
|
if (error instanceof UnexpectedError) {
|
|
3977
4089
|
throw error;
|
|
3978
4090
|
}
|
|
@@ -4593,9 +4705,7 @@ async function executePipeline(options) {
|
|
|
4593
4705
|
await Promise.all(resolving);
|
|
4594
4706
|
}
|
|
4595
4707
|
catch (error /* <- Note: [3] */) {
|
|
4596
|
-
|
|
4597
|
-
throw error;
|
|
4598
|
-
}
|
|
4708
|
+
assertsError(error);
|
|
4599
4709
|
// Note: No need to rethrow UnexpectedError
|
|
4600
4710
|
// if (error instanceof UnexpectedError) {
|
|
4601
4711
|
// Note: Count usage, [๐ง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐คนโโ๏ธ]
|
|
@@ -5311,9 +5421,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
|
|
|
5311
5421
|
return await fetch(urlOrRequest, init);
|
|
5312
5422
|
}
|
|
5313
5423
|
catch (error) {
|
|
5314
|
-
|
|
5315
|
-
throw error;
|
|
5316
|
-
}
|
|
5424
|
+
assertsError(error);
|
|
5317
5425
|
let url;
|
|
5318
5426
|
if (typeof urlOrRequest === 'string') {
|
|
5319
5427
|
url = urlOrRequest;
|
|
@@ -5544,9 +5652,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5544
5652
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5545
5653
|
}
|
|
5546
5654
|
catch (error) {
|
|
5547
|
-
|
|
5548
|
-
throw error;
|
|
5549
|
-
}
|
|
5655
|
+
assertsError(error);
|
|
5550
5656
|
console.warn(error);
|
|
5551
5657
|
// <- TODO: [๐ฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5552
5658
|
}
|
|
@@ -6344,6 +6450,8 @@ function parseNumber(value) {
|
|
|
6344
6450
|
*/
|
|
6345
6451
|
|
|
6346
6452
|
/**
|
|
6453
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6454
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6347
6455
|
* Parses the expect command
|
|
6348
6456
|
*
|
|
6349
6457
|
* @see `documentationUrl` for more details
|
|
@@ -6435,9 +6543,7 @@ const expectCommandParser = {
|
|
|
6435
6543
|
};
|
|
6436
6544
|
}
|
|
6437
6545
|
catch (error) {
|
|
6438
|
-
|
|
6439
|
-
throw error;
|
|
6440
|
-
}
|
|
6546
|
+
assertsError(error);
|
|
6441
6547
|
throw new ParseError(spaceTrim((block) => `
|
|
6442
6548
|
Invalid FORMAT command
|
|
6443
6549
|
${block(error.message)}:
|
|
@@ -10531,9 +10637,7 @@ function isValidPipelineString(pipelineString) {
|
|
|
10531
10637
|
return true;
|
|
10532
10638
|
}
|
|
10533
10639
|
catch (error) {
|
|
10534
|
-
|
|
10535
|
-
throw error;
|
|
10536
|
-
}
|
|
10640
|
+
assertsError(error);
|
|
10537
10641
|
return false;
|
|
10538
10642
|
}
|
|
10539
10643
|
}
|
|
@@ -10628,6 +10732,40 @@ function book(strings, ...values) {
|
|
|
10628
10732
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
10629
10733
|
*/
|
|
10630
10734
|
|
|
10735
|
+
/**
|
|
10736
|
+
* Convert identification to Promptbook token
|
|
10737
|
+
*
|
|
10738
|
+
* @param identification
|
|
10739
|
+
*
|
|
10740
|
+
* @public exported from `@promptbook/core`
|
|
10741
|
+
*/
|
|
10742
|
+
function identificationToPromptbookToken(identification) {
|
|
10743
|
+
const { appId, userId, userToken } = identification;
|
|
10744
|
+
const promptbookToken = `${appId}-${userId}-${userToken}`;
|
|
10745
|
+
return promptbookToken;
|
|
10746
|
+
}
|
|
10747
|
+
|
|
10748
|
+
/**
|
|
10749
|
+
* Convert Promptbook token to identification
|
|
10750
|
+
*
|
|
10751
|
+
* @param promptbookToken
|
|
10752
|
+
*
|
|
10753
|
+
* @public exported from `@promptbook/core`
|
|
10754
|
+
*/
|
|
10755
|
+
function promptbookTokenToIdentification(promptbookToken) {
|
|
10756
|
+
const [appId, userId, userToken] = promptbookToken.split('-');
|
|
10757
|
+
if (!appId || !userId || !userToken) {
|
|
10758
|
+
throw new Error(`Invalid promptbook token: ${promptbookToken}`);
|
|
10759
|
+
}
|
|
10760
|
+
const identification = {
|
|
10761
|
+
appId,
|
|
10762
|
+
userId,
|
|
10763
|
+
userToken,
|
|
10764
|
+
isAnonymous: false,
|
|
10765
|
+
};
|
|
10766
|
+
return identification;
|
|
10767
|
+
}
|
|
10768
|
+
|
|
10631
10769
|
/**
|
|
10632
10770
|
* Metadata of the scraper
|
|
10633
10771
|
*
|
|
@@ -10917,5 +11055,5 @@ class PrefixStorage {
|
|
|
10917
11055
|
}
|
|
10918
11056
|
}
|
|
10919
11057
|
|
|
10920
|
-
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,
|
|
11058
|
+
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 };
|
|
10921
11059
|
//# sourceMappingURL=index.es.js.map
|