@promptbook/core 0.89.0-8 → 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 +538 -379
- 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 +12 -4
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -6
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +24 -14
- 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 +8 -2
- 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/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/$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 +15 -4
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
- package/esm/typings/src/remote-server/openapi.d.ts +187 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +9 -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 +1 -2
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +57 -38
- 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 +26 -0
- package/package.json +7 -3
- package/umd/index.umd.js +543 -380
- 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';
|
|
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
|
/**
|
|
@@ -2013,6 +2076,19 @@ class NotYetImplementedError extends Error {
|
|
|
2013
2076
|
}
|
|
2014
2077
|
}
|
|
2015
2078
|
|
|
2079
|
+
/**
|
|
2080
|
+
* Error thrown when a fetch request fails
|
|
2081
|
+
*
|
|
2082
|
+
* @public exported from `@promptbook/core`
|
|
2083
|
+
*/
|
|
2084
|
+
class PromptbookFetchError extends Error {
|
|
2085
|
+
constructor(message) {
|
|
2086
|
+
super(message);
|
|
2087
|
+
this.name = 'PromptbookFetchError';
|
|
2088
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2016
2092
|
/**
|
|
2017
2093
|
* Index of all custom errors
|
|
2018
2094
|
*
|
|
@@ -2033,7 +2109,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2033
2109
|
PipelineExecutionError,
|
|
2034
2110
|
PipelineLogicError,
|
|
2035
2111
|
PipelineUrlError,
|
|
2112
|
+
AuthenticationError,
|
|
2113
|
+
PromptbookFetchError,
|
|
2036
2114
|
UnexpectedError,
|
|
2115
|
+
WrappedError,
|
|
2037
2116
|
// TODO: [🪑]> VersionMismatchError,
|
|
2038
2117
|
};
|
|
2039
2118
|
/**
|
|
@@ -2050,7 +2129,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
2050
2129
|
TypeError,
|
|
2051
2130
|
URIError,
|
|
2052
2131
|
AggregateError,
|
|
2053
|
-
AuthenticationError,
|
|
2054
2132
|
/*
|
|
2055
2133
|
Note: Not widely supported
|
|
2056
2134
|
> InternalError,
|
|
@@ -2173,8 +2251,8 @@ function createTask(options) {
|
|
|
2173
2251
|
updatedAt = new Date();
|
|
2174
2252
|
errors.push(...executionResult.errors);
|
|
2175
2253
|
warnings.push(...executionResult.warnings);
|
|
2176
|
-
// <- TODO:
|
|
2177
|
-
// 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`
|
|
2178
2256
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2179
2257
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2180
2258
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2184,6 +2262,7 @@ function createTask(options) {
|
|
|
2184
2262
|
partialResultSubject.next(executionResult);
|
|
2185
2263
|
}
|
|
2186
2264
|
catch (error) {
|
|
2265
|
+
assertsError(error);
|
|
2187
2266
|
status = 'ERROR';
|
|
2188
2267
|
errors.push(error);
|
|
2189
2268
|
partialResultSubject.error(error);
|
|
@@ -2329,13 +2408,19 @@ function valueToString(value) {
|
|
|
2329
2408
|
return value.toISOString();
|
|
2330
2409
|
}
|
|
2331
2410
|
else {
|
|
2332
|
-
|
|
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
|
+
}
|
|
2333
2420
|
}
|
|
2334
2421
|
}
|
|
2335
2422
|
catch (error) {
|
|
2336
|
-
|
|
2337
|
-
throw error;
|
|
2338
|
-
}
|
|
2423
|
+
assertsError(error);
|
|
2339
2424
|
console.error(error);
|
|
2340
2425
|
return VALUE_STRINGS.unserializable;
|
|
2341
2426
|
}
|
|
@@ -2507,9 +2592,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
2507
2592
|
}
|
|
2508
2593
|
}
|
|
2509
2594
|
catch (error) {
|
|
2510
|
-
|
|
2511
|
-
throw error;
|
|
2512
|
-
}
|
|
2595
|
+
assertsError(error);
|
|
2513
2596
|
throw new ParseError(spaceTrim$1((block) => `
|
|
2514
2597
|
Can not extract variables from the script
|
|
2515
2598
|
${block(error.stack || error.message)}
|
|
@@ -2628,6 +2711,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
2628
2711
|
// encoding: 'utf-8',
|
|
2629
2712
|
});
|
|
2630
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
|
+
|
|
2631
2736
|
/**
|
|
2632
2737
|
* Definition for CSV spreadsheet
|
|
2633
2738
|
*
|
|
@@ -2638,7 +2743,7 @@ const CsvFormatDefinition = {
|
|
|
2638
2743
|
formatName: 'CSV',
|
|
2639
2744
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
2640
2745
|
isValid(value, settings, schema) {
|
|
2641
|
-
return
|
|
2746
|
+
return isValidCsvString(value);
|
|
2642
2747
|
},
|
|
2643
2748
|
canBeValid(partialValue, settings, schema) {
|
|
2644
2749
|
return true;
|
|
@@ -2792,6 +2897,30 @@ const TextFormatDefinition = {
|
|
|
2792
2897
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
2793
2898
|
*/
|
|
2794
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
|
+
|
|
2795
2924
|
/**
|
|
2796
2925
|
* Definition for XML format
|
|
2797
2926
|
*
|
|
@@ -2801,7 +2930,7 @@ const XmlFormatDefinition = {
|
|
|
2801
2930
|
formatName: 'XML',
|
|
2802
2931
|
mimeType: 'application/xml',
|
|
2803
2932
|
isValid(value, settings, schema) {
|
|
2804
|
-
return
|
|
2933
|
+
return isValidXmlString(value);
|
|
2805
2934
|
},
|
|
2806
2935
|
canBeValid(partialValue, settings, schema) {
|
|
2807
2936
|
return true;
|
|
@@ -2998,14 +3127,15 @@ class MultipleLlmExecutionTools {
|
|
|
2998
3127
|
}
|
|
2999
3128
|
}
|
|
3000
3129
|
catch (error) {
|
|
3001
|
-
|
|
3130
|
+
assertsError(error);
|
|
3131
|
+
if (error instanceof UnexpectedError) {
|
|
3002
3132
|
throw error;
|
|
3003
3133
|
}
|
|
3004
3134
|
errors.push({ llmExecutionTools, error });
|
|
3005
3135
|
}
|
|
3006
3136
|
}
|
|
3007
3137
|
if (errors.length === 1) {
|
|
3008
|
-
throw errors[0];
|
|
3138
|
+
throw errors[0].error;
|
|
3009
3139
|
}
|
|
3010
3140
|
else if (errors.length > 1) {
|
|
3011
3141
|
throw new PipelineExecutionError(
|
|
@@ -3884,9 +4014,7 @@ async function executeAttempts(options) {
|
|
|
3884
4014
|
break scripts;
|
|
3885
4015
|
}
|
|
3886
4016
|
catch (error) {
|
|
3887
|
-
|
|
3888
|
-
throw error;
|
|
3889
|
-
}
|
|
4017
|
+
assertsError(error);
|
|
3890
4018
|
if (error instanceof UnexpectedError) {
|
|
3891
4019
|
throw error;
|
|
3892
4020
|
}
|
|
@@ -3956,9 +4084,7 @@ async function executeAttempts(options) {
|
|
|
3956
4084
|
break scripts;
|
|
3957
4085
|
}
|
|
3958
4086
|
catch (error) {
|
|
3959
|
-
|
|
3960
|
-
throw error;
|
|
3961
|
-
}
|
|
4087
|
+
assertsError(error);
|
|
3962
4088
|
if (error instanceof UnexpectedError) {
|
|
3963
4089
|
throw error;
|
|
3964
4090
|
}
|
|
@@ -4579,9 +4705,7 @@ async function executePipeline(options) {
|
|
|
4579
4705
|
await Promise.all(resolving);
|
|
4580
4706
|
}
|
|
4581
4707
|
catch (error /* <- Note: [3] */) {
|
|
4582
|
-
|
|
4583
|
-
throw error;
|
|
4584
|
-
}
|
|
4708
|
+
assertsError(error);
|
|
4585
4709
|
// Note: No need to rethrow UnexpectedError
|
|
4586
4710
|
// if (error instanceof UnexpectedError) {
|
|
4587
4711
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5290,17 +5414,22 @@ function titleToName(value) {
|
|
|
5290
5414
|
/**
|
|
5291
5415
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5292
5416
|
*
|
|
5293
|
-
* @
|
|
5417
|
+
* @public exported from `@promptbook/core`
|
|
5294
5418
|
*/
|
|
5295
|
-
const
|
|
5419
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5296
5420
|
try {
|
|
5297
|
-
return await fetch(
|
|
5421
|
+
return await fetch(urlOrRequest, init);
|
|
5298
5422
|
}
|
|
5299
5423
|
catch (error) {
|
|
5300
|
-
|
|
5301
|
-
|
|
5424
|
+
assertsError(error);
|
|
5425
|
+
let url;
|
|
5426
|
+
if (typeof urlOrRequest === 'string') {
|
|
5427
|
+
url = urlOrRequest;
|
|
5428
|
+
}
|
|
5429
|
+
else if (urlOrRequest instanceof Request) {
|
|
5430
|
+
url = urlOrRequest.url;
|
|
5302
5431
|
}
|
|
5303
|
-
throw new
|
|
5432
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
5304
5433
|
Can not fetch "${url}"
|
|
5305
5434
|
|
|
5306
5435
|
Fetch error:
|
|
@@ -5321,7 +5450,7 @@ const scraperFetch = async (url, init) => {
|
|
|
5321
5450
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5322
5451
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5323
5452
|
var _a;
|
|
5324
|
-
const { fetch =
|
|
5453
|
+
const { fetch = promptbookFetch } = tools;
|
|
5325
5454
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5326
5455
|
let { name } = knowledgeSource;
|
|
5327
5456
|
const { rootDirname = null,
|
|
@@ -5523,9 +5652,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5523
5652
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5524
5653
|
}
|
|
5525
5654
|
catch (error) {
|
|
5526
|
-
|
|
5527
|
-
throw error;
|
|
5528
|
-
}
|
|
5655
|
+
assertsError(error);
|
|
5529
5656
|
console.warn(error);
|
|
5530
5657
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5531
5658
|
}
|
|
@@ -6323,6 +6450,8 @@ function parseNumber(value) {
|
|
|
6323
6450
|
*/
|
|
6324
6451
|
|
|
6325
6452
|
/**
|
|
6453
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6454
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6326
6455
|
* Parses the expect command
|
|
6327
6456
|
*
|
|
6328
6457
|
* @see `documentationUrl` for more details
|
|
@@ -6414,9 +6543,7 @@ const expectCommandParser = {
|
|
|
6414
6543
|
};
|
|
6415
6544
|
}
|
|
6416
6545
|
catch (error) {
|
|
6417
|
-
|
|
6418
|
-
throw error;
|
|
6419
|
-
}
|
|
6546
|
+
assertsError(error);
|
|
6420
6547
|
throw new ParseError(spaceTrim((block) => `
|
|
6421
6548
|
Invalid FORMAT command
|
|
6422
6549
|
${block(error.message)}:
|
|
@@ -10510,9 +10637,7 @@ function isValidPipelineString(pipelineString) {
|
|
|
10510
10637
|
return true;
|
|
10511
10638
|
}
|
|
10512
10639
|
catch (error) {
|
|
10513
|
-
|
|
10514
|
-
throw error;
|
|
10515
|
-
}
|
|
10640
|
+
assertsError(error);
|
|
10516
10641
|
return false;
|
|
10517
10642
|
}
|
|
10518
10643
|
}
|
|
@@ -10607,6 +10732,40 @@ function book(strings, ...values) {
|
|
|
10607
10732
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10608
10733
|
*/
|
|
10609
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
|
+
|
|
10610
10769
|
/**
|
|
10611
10770
|
* Metadata of the scraper
|
|
10612
10771
|
*
|
|
@@ -10896,5 +11055,5 @@ class PrefixStorage {
|
|
|
10896
11055
|
}
|
|
10897
11056
|
}
|
|
10898
11057
|
|
|
10899
|
-
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 };
|
|
10900
11059
|
//# sourceMappingURL=index.es.js.map
|