@promptbook/core 0.89.0-3 → 0.89.0-30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/esm/index.es.js +526 -383
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +40 -0
- package/esm/typings/src/_packages/core.index.d.ts +20 -8
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +24 -12
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +28 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +24 -26
- package/esm/typings/src/errors/0-index.d.ts +9 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +11 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +45 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
- package/esm/typings/src/remote-server/openapi.d.ts +187 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -4
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +84 -9
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +19 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +7 -3
- package/umd/index.umd.js +535 -386
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
- package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/umd/index.umd.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
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-30';
|
|
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 @@
|
|
|
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 prettier.format(content, {
|
|
221
|
-
parser: 'markdown',
|
|
222
|
-
plugins: [parserHtml__default["default"]],
|
|
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__default["default"](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 @@
|
|
|
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 @@
|
|
|
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,6 +355,7 @@
|
|
|
572
355
|
*/
|
|
573
356
|
const DEFAULT_BOOKS_DIRNAME = './books';
|
|
574
357
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
358
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
575
359
|
/**
|
|
576
360
|
* Where to store the temporary downloads
|
|
577
361
|
*
|
|
@@ -596,6 +380,27 @@
|
|
|
596
380
|
* @public exported from `@promptbook/core`
|
|
597
381
|
*/
|
|
598
382
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
383
|
+
/**
|
|
384
|
+
* Id of application for the CLI when using remote server
|
|
385
|
+
*
|
|
386
|
+
* @public exported from `@promptbook/core`
|
|
387
|
+
*/
|
|
388
|
+
const CLI_APP_ID = 'cli';
|
|
389
|
+
/**
|
|
390
|
+
* Id of application for the playground
|
|
391
|
+
*
|
|
392
|
+
* @public exported from `@promptbook/core`
|
|
393
|
+
*/
|
|
394
|
+
const PLAYGROUND_APP_ID = 'playground';
|
|
395
|
+
/*
|
|
396
|
+
TODO: [🌃]
|
|
397
|
+
/**
|
|
398
|
+
* Id of application for the wizzard when using remote server
|
|
399
|
+
*
|
|
400
|
+
* @public exported from `@promptbook/core`
|
|
401
|
+
* /
|
|
402
|
+
ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
|
|
403
|
+
*/
|
|
599
404
|
/**
|
|
600
405
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
601
406
|
*
|
|
@@ -612,17 +417,11 @@
|
|
|
612
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.
|
|
613
418
|
};
|
|
614
419
|
/**
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
* @public exported from `@promptbook/core`
|
|
618
|
-
*/
|
|
619
|
-
const DEFAULT_REMOTE_URL = 'https://api.pavolhejny.com/';
|
|
620
|
-
/**
|
|
621
|
-
* @@@
|
|
420
|
+
* Default remote server URL for the Promptbook
|
|
622
421
|
*
|
|
623
422
|
* @public exported from `@promptbook/core`
|
|
624
423
|
*/
|
|
625
|
-
const
|
|
424
|
+
const DEFAULT_REMOTE_SERVER_URL = REMOTE_SERVER_URLS[0].urls[0];
|
|
626
425
|
// <- TODO: [🧜♂️]
|
|
627
426
|
/**
|
|
628
427
|
* @@@
|
|
@@ -652,29 +451,376 @@
|
|
|
652
451
|
exports.DEFAULT_IS_VERBOSE = isVerbose;
|
|
653
452
|
}
|
|
654
453
|
/**
|
|
655
|
-
* @@@
|
|
656
|
-
*
|
|
657
|
-
* @public exported from `@promptbook/core`
|
|
658
|
-
*/
|
|
659
|
-
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
660
|
-
/**
|
|
661
|
-
* Function name for generated function via `ptbk make` to get the pipeline collection
|
|
662
|
-
*
|
|
663
|
-
* @public exported from `@promptbook/core`
|
|
664
|
-
*/
|
|
665
|
-
const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = `getPipelineCollection`;
|
|
666
|
-
/**
|
|
667
|
-
* @@@
|
|
668
|
-
*
|
|
669
|
-
* @private within the repository
|
|
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__default["default"]((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.spaceTrim((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.spaceTrim(`
|
|
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
|
+
* @public exported from `@promptbook/utils`
|
|
599
|
+
*/
|
|
600
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
601
|
+
try {
|
|
602
|
+
JSON.parse(value);
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
assertsError(error);
|
|
607
|
+
if (error.message.includes('Unexpected token')) {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
616
|
+
* 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.
|
|
617
|
+
*
|
|
618
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
619
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
620
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
621
|
+
* @public exported from `@promptbook/core`
|
|
622
|
+
*/
|
|
623
|
+
function validatePipelineString(pipelineString) {
|
|
624
|
+
if (isValidJsonString(pipelineString)) {
|
|
625
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
626
|
+
}
|
|
627
|
+
else if (isValidUrl(pipelineString)) {
|
|
628
|
+
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
629
|
+
}
|
|
630
|
+
else if (isValidFilePath(pipelineString)) {
|
|
631
|
+
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
632
|
+
}
|
|
633
|
+
else if (isValidEmail(pipelineString)) {
|
|
634
|
+
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
635
|
+
}
|
|
636
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
637
|
+
return pipelineString;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
641
|
+
*/
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Prettify the html code
|
|
645
|
+
*
|
|
646
|
+
* @param content raw html code
|
|
647
|
+
* @returns formatted html code
|
|
648
|
+
* @private withing the package because of HUGE size of prettier dependency
|
|
649
|
+
*/
|
|
650
|
+
function prettifyMarkdown(content) {
|
|
651
|
+
try {
|
|
652
|
+
return prettier.format(content, {
|
|
653
|
+
parser: 'markdown',
|
|
654
|
+
plugins: [parserHtml__default["default"]],
|
|
655
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
656
|
+
endOfLine: 'lf',
|
|
657
|
+
tabWidth: 4,
|
|
658
|
+
singleQuote: true,
|
|
659
|
+
trailingComma: 'all',
|
|
660
|
+
arrowParens: 'always',
|
|
661
|
+
printWidth: 120,
|
|
662
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
663
|
+
jsxBracketSameLine: false,
|
|
664
|
+
bracketSpacing: true,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
catch (error) {
|
|
668
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
669
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
670
|
+
error,
|
|
671
|
+
html: content,
|
|
672
|
+
});
|
|
673
|
+
return content;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Makes first letter of a string uppercase
|
|
679
|
+
*
|
|
680
|
+
* @public exported from `@promptbook/utils`
|
|
681
|
+
*/
|
|
682
|
+
function capitalize(word) {
|
|
683
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Converts promptbook in JSON format to string format
|
|
688
|
+
*
|
|
689
|
+
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
690
|
+
* @param pipelineJson Promptbook in JSON format (.bookc)
|
|
691
|
+
* @returns Promptbook in string format (.book.md)
|
|
692
|
+
* @public exported from `@promptbook/core`
|
|
693
|
+
*/
|
|
694
|
+
function pipelineJsonToString(pipelineJson) {
|
|
695
|
+
const { title, pipelineUrl, bookVersion, description, parameters, tasks } = pipelineJson;
|
|
696
|
+
let pipelineString = `# ${title}`;
|
|
697
|
+
if (description) {
|
|
698
|
+
pipelineString += '\n\n';
|
|
699
|
+
pipelineString += description;
|
|
700
|
+
}
|
|
701
|
+
const commands = [];
|
|
702
|
+
if (pipelineUrl) {
|
|
703
|
+
commands.push(`PIPELINE URL ${pipelineUrl}`);
|
|
704
|
+
}
|
|
705
|
+
if (bookVersion !== `undefined`) {
|
|
706
|
+
commands.push(`BOOK VERSION ${bookVersion}`);
|
|
707
|
+
}
|
|
708
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
709
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
710
|
+
for (const parameter of parameters.filter(({ isInput }) => isInput)) {
|
|
711
|
+
commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
712
|
+
}
|
|
713
|
+
for (const parameter of parameters.filter(({ isOutput }) => isOutput)) {
|
|
714
|
+
commands.push(`OUTPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
|
|
715
|
+
}
|
|
716
|
+
pipelineString += '\n\n';
|
|
717
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
718
|
+
for (const task of tasks) {
|
|
719
|
+
const {
|
|
720
|
+
/* Note: Not using:> name, */
|
|
721
|
+
title, description,
|
|
722
|
+
/* Note: dependentParameterNames, */
|
|
723
|
+
jokerParameterNames: jokers, taskType, content, postprocessingFunctionNames: postprocessing, expectations, format, resultingParameterName, } = task;
|
|
724
|
+
pipelineString += '\n\n';
|
|
725
|
+
pipelineString += `## ${title}`;
|
|
726
|
+
if (description) {
|
|
727
|
+
pipelineString += '\n\n';
|
|
728
|
+
pipelineString += description;
|
|
729
|
+
}
|
|
730
|
+
const commands = [];
|
|
731
|
+
let contentLanguage = 'text';
|
|
732
|
+
if (taskType === 'PROMPT_TASK') {
|
|
733
|
+
const { modelRequirements } = task;
|
|
734
|
+
const { modelName, modelVariant } = modelRequirements || {};
|
|
735
|
+
// Note: Do nothing, it is default
|
|
736
|
+
// commands.push(`PROMPT`);
|
|
737
|
+
if (modelVariant) {
|
|
738
|
+
commands.push(`MODEL VARIANT ${capitalize(modelVariant)}`);
|
|
739
|
+
}
|
|
740
|
+
if (modelName) {
|
|
741
|
+
commands.push(`MODEL NAME \`${modelName}\``);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
else if (taskType === 'SIMPLE_TASK') {
|
|
745
|
+
commands.push(`SIMPLE TEMPLATE`);
|
|
746
|
+
// Note: Nothing special here
|
|
747
|
+
}
|
|
748
|
+
else if (taskType === 'SCRIPT_TASK') {
|
|
749
|
+
commands.push(`SCRIPT`);
|
|
750
|
+
if (task.contentLanguage) {
|
|
751
|
+
contentLanguage = task.contentLanguage;
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
contentLanguage = '';
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
else if (taskType === 'DIALOG_TASK') {
|
|
758
|
+
commands.push(`DIALOG`);
|
|
759
|
+
// Note: Nothing special here
|
|
760
|
+
} // <- }else if([🅱]
|
|
761
|
+
if (jokers) {
|
|
762
|
+
for (const joker of jokers) {
|
|
763
|
+
commands.push(`JOKER {${joker}}`);
|
|
764
|
+
}
|
|
765
|
+
} /* not else */
|
|
766
|
+
if (postprocessing) {
|
|
767
|
+
for (const postprocessingFunctionName of postprocessing) {
|
|
768
|
+
commands.push(`POSTPROCESSING \`${postprocessingFunctionName}\``);
|
|
769
|
+
}
|
|
770
|
+
} /* not else */
|
|
771
|
+
if (expectations) {
|
|
772
|
+
for (const [unit, { min, max }] of Object.entries(expectations)) {
|
|
773
|
+
if (min === max) {
|
|
774
|
+
commands.push(`EXPECT EXACTLY ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
if (min !== undefined) {
|
|
778
|
+
commands.push(`EXPECT MIN ${min} ${capitalize(unit + (min > 1 ? 's' : ''))}`);
|
|
779
|
+
} /* not else */
|
|
780
|
+
if (max !== undefined) {
|
|
781
|
+
commands.push(`EXPECT MAX ${max} ${capitalize(unit + (max > 1 ? 's' : ''))}`);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
} /* not else */
|
|
786
|
+
if (format) {
|
|
787
|
+
if (format === 'JSON') {
|
|
788
|
+
// TODO: @deprecated remove
|
|
789
|
+
commands.push(`FORMAT JSON`);
|
|
790
|
+
}
|
|
791
|
+
} /* not else */
|
|
792
|
+
pipelineString += '\n\n';
|
|
793
|
+
pipelineString += commands.map((command) => `- ${command}`).join('\n');
|
|
794
|
+
pipelineString += '\n\n';
|
|
795
|
+
pipelineString += '```' + contentLanguage;
|
|
796
|
+
pipelineString += '\n';
|
|
797
|
+
pipelineString += spaceTrim__default["default"](content);
|
|
798
|
+
// <- TODO: [main] !!3 Escape
|
|
799
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
800
|
+
pipelineString += '\n';
|
|
801
|
+
pipelineString += '```';
|
|
802
|
+
pipelineString += '\n\n';
|
|
803
|
+
pipelineString += `\`-> {${resultingParameterName}}\``; // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
804
|
+
}
|
|
805
|
+
return validatePipelineString(pipelineString);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* @private internal utility of `pipelineJsonToString`
|
|
670
809
|
*/
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
810
|
+
function taskParameterJsonToString(taskParameterJson) {
|
|
811
|
+
const { name, description } = taskParameterJson;
|
|
812
|
+
let parameterString = `{${name}}`;
|
|
813
|
+
if (description) {
|
|
814
|
+
parameterString = `${parameterString} ${description}`;
|
|
815
|
+
}
|
|
816
|
+
return parameterString;
|
|
817
|
+
}
|
|
675
818
|
/**
|
|
676
|
-
*
|
|
677
|
-
* TODO: [🧠]
|
|
819
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
|
|
820
|
+
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
821
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
822
|
+
* TODO: [🏛] Escape all
|
|
823
|
+
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
678
824
|
*/
|
|
679
825
|
|
|
680
826
|
/**
|
|
@@ -719,74 +865,6 @@
|
|
|
719
865
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
720
866
|
*/
|
|
721
867
|
|
|
722
|
-
/**
|
|
723
|
-
* Make error report URL for the given error
|
|
724
|
-
*
|
|
725
|
-
* @private private within the repository
|
|
726
|
-
*/
|
|
727
|
-
function getErrorReportUrl(error) {
|
|
728
|
-
const report = {
|
|
729
|
-
title: `🐜 Error report from ${NAME}`,
|
|
730
|
-
body: spaceTrim__default["default"]((block) => `
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
734
|
-
|
|
735
|
-
\`\`\`
|
|
736
|
-
${block(error.message || '(no error message)')}
|
|
737
|
-
\`\`\`
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
## More info:
|
|
741
|
-
|
|
742
|
-
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
743
|
-
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
744
|
-
- **Time:** ${new Date().toISOString()}
|
|
745
|
-
|
|
746
|
-
<details>
|
|
747
|
-
<summary>Stack trace:</summary>
|
|
748
|
-
|
|
749
|
-
## Stack trace:
|
|
750
|
-
|
|
751
|
-
\`\`\`stacktrace
|
|
752
|
-
${block(error.stack || '(empty)')}
|
|
753
|
-
\`\`\`
|
|
754
|
-
</details>
|
|
755
|
-
|
|
756
|
-
`),
|
|
757
|
-
};
|
|
758
|
-
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
759
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
760
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
761
|
-
reportUrl.searchParams.set('title', report.title);
|
|
762
|
-
reportUrl.searchParams.set('body', report.body);
|
|
763
|
-
return reportUrl;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
768
|
-
*
|
|
769
|
-
* @public exported from `@promptbook/core`
|
|
770
|
-
*/
|
|
771
|
-
class UnexpectedError extends Error {
|
|
772
|
-
constructor(message) {
|
|
773
|
-
super(spaceTrim.spaceTrim((block) => `
|
|
774
|
-
${block(message)}
|
|
775
|
-
|
|
776
|
-
Note: This error should not happen.
|
|
777
|
-
It's probbably a bug in the pipeline collection
|
|
778
|
-
|
|
779
|
-
Please report issue:
|
|
780
|
-
${block(getErrorReportUrl(new Error(message)).href)}
|
|
781
|
-
|
|
782
|
-
Or contact us on ${ADMIN_EMAIL}
|
|
783
|
-
|
|
784
|
-
`));
|
|
785
|
-
this.name = 'UnexpectedError';
|
|
786
|
-
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
|
|
790
868
|
/**
|
|
791
869
|
* Checks if the value is [🚉] serializable as JSON
|
|
792
870
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -878,9 +956,7 @@
|
|
|
878
956
|
JSON.stringify(value); // <- TODO: [0]
|
|
879
957
|
}
|
|
880
958
|
catch (error) {
|
|
881
|
-
|
|
882
|
-
throw error;
|
|
883
|
-
}
|
|
959
|
+
assertsError(error);
|
|
884
960
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
885
961
|
\`${name}\` is not serializable
|
|
886
962
|
|
|
@@ -1860,7 +1936,7 @@
|
|
|
1860
1936
|
}
|
|
1861
1937
|
}
|
|
1862
1938
|
/**
|
|
1863
|
-
* TODO:
|
|
1939
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
1864
1940
|
*/
|
|
1865
1941
|
|
|
1866
1942
|
/**
|
|
@@ -1893,6 +1969,19 @@
|
|
|
1893
1969
|
}
|
|
1894
1970
|
}
|
|
1895
1971
|
|
|
1972
|
+
/**
|
|
1973
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1974
|
+
*
|
|
1975
|
+
* @public exported from `@promptbook/core`
|
|
1976
|
+
*/
|
|
1977
|
+
class AuthenticationError extends Error {
|
|
1978
|
+
constructor(message) {
|
|
1979
|
+
super(message);
|
|
1980
|
+
this.name = 'AuthenticationError';
|
|
1981
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1896
1985
|
/**
|
|
1897
1986
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1898
1987
|
*
|
|
@@ -1984,6 +2073,19 @@
|
|
|
1984
2073
|
}
|
|
1985
2074
|
}
|
|
1986
2075
|
|
|
2076
|
+
/**
|
|
2077
|
+
* Error thrown when a fetch request fails
|
|
2078
|
+
*
|
|
2079
|
+
* @public exported from `@promptbook/core`
|
|
2080
|
+
*/
|
|
2081
|
+
class PromptbookFetchError extends Error {
|
|
2082
|
+
constructor(message) {
|
|
2083
|
+
super(message);
|
|
2084
|
+
this.name = 'PromptbookFetchError';
|
|
2085
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
1987
2089
|
/**
|
|
1988
2090
|
* Index of all custom errors
|
|
1989
2091
|
*
|
|
@@ -2004,7 +2106,10 @@
|
|
|
2004
2106
|
PipelineExecutionError,
|
|
2005
2107
|
PipelineLogicError,
|
|
2006
2108
|
PipelineUrlError,
|
|
2109
|
+
AuthenticationError,
|
|
2110
|
+
PromptbookFetchError,
|
|
2007
2111
|
UnexpectedError,
|
|
2112
|
+
WrappedError,
|
|
2008
2113
|
// TODO: [🪑]> VersionMismatchError,
|
|
2009
2114
|
};
|
|
2010
2115
|
/**
|
|
@@ -2143,8 +2248,8 @@
|
|
|
2143
2248
|
updatedAt = new Date();
|
|
2144
2249
|
errors.push(...executionResult.errors);
|
|
2145
2250
|
warnings.push(...executionResult.warnings);
|
|
2146
|
-
// <- TODO:
|
|
2147
|
-
// TODO: [🧠]
|
|
2251
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2252
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2148
2253
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2149
2254
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2150
2255
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2154,6 +2259,7 @@
|
|
|
2154
2259
|
partialResultSubject.next(executionResult);
|
|
2155
2260
|
}
|
|
2156
2261
|
catch (error) {
|
|
2262
|
+
assertsError(error);
|
|
2157
2263
|
status = 'ERROR';
|
|
2158
2264
|
errors.push(error);
|
|
2159
2265
|
partialResultSubject.error(error);
|
|
@@ -2220,6 +2326,10 @@
|
|
|
2220
2326
|
|
|
2221
2327
|
Cannot serialize error with name "${name}"
|
|
2222
2328
|
|
|
2329
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2330
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2331
|
+
|
|
2332
|
+
|
|
2223
2333
|
${block(stack || message)}
|
|
2224
2334
|
|
|
2225
2335
|
`));
|
|
@@ -2295,13 +2405,19 @@
|
|
|
2295
2405
|
return value.toISOString();
|
|
2296
2406
|
}
|
|
2297
2407
|
else {
|
|
2298
|
-
|
|
2408
|
+
try {
|
|
2409
|
+
return JSON.stringify(value);
|
|
2410
|
+
}
|
|
2411
|
+
catch (error) {
|
|
2412
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2413
|
+
return VALUE_STRINGS.circular;
|
|
2414
|
+
}
|
|
2415
|
+
throw error;
|
|
2416
|
+
}
|
|
2299
2417
|
}
|
|
2300
2418
|
}
|
|
2301
2419
|
catch (error) {
|
|
2302
|
-
|
|
2303
|
-
throw error;
|
|
2304
|
-
}
|
|
2420
|
+
assertsError(error);
|
|
2305
2421
|
console.error(error);
|
|
2306
2422
|
return VALUE_STRINGS.unserializable;
|
|
2307
2423
|
}
|
|
@@ -2473,9 +2589,7 @@
|
|
|
2473
2589
|
}
|
|
2474
2590
|
}
|
|
2475
2591
|
catch (error) {
|
|
2476
|
-
|
|
2477
|
-
throw error;
|
|
2478
|
-
}
|
|
2592
|
+
assertsError(error);
|
|
2479
2593
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
2480
2594
|
Can not extract variables from the script
|
|
2481
2595
|
${block(error.stack || error.message)}
|
|
@@ -2964,14 +3078,15 @@
|
|
|
2964
3078
|
}
|
|
2965
3079
|
}
|
|
2966
3080
|
catch (error) {
|
|
2967
|
-
|
|
3081
|
+
assertsError(error);
|
|
3082
|
+
if (error instanceof UnexpectedError) {
|
|
2968
3083
|
throw error;
|
|
2969
3084
|
}
|
|
2970
3085
|
errors.push({ llmExecutionTools, error });
|
|
2971
3086
|
}
|
|
2972
3087
|
}
|
|
2973
3088
|
if (errors.length === 1) {
|
|
2974
|
-
throw errors[0];
|
|
3089
|
+
throw errors[0].error;
|
|
2975
3090
|
}
|
|
2976
3091
|
else if (errors.length > 1) {
|
|
2977
3092
|
throw new PipelineExecutionError(
|
|
@@ -3850,9 +3965,7 @@
|
|
|
3850
3965
|
break scripts;
|
|
3851
3966
|
}
|
|
3852
3967
|
catch (error) {
|
|
3853
|
-
|
|
3854
|
-
throw error;
|
|
3855
|
-
}
|
|
3968
|
+
assertsError(error);
|
|
3856
3969
|
if (error instanceof UnexpectedError) {
|
|
3857
3970
|
throw error;
|
|
3858
3971
|
}
|
|
@@ -3922,9 +4035,7 @@
|
|
|
3922
4035
|
break scripts;
|
|
3923
4036
|
}
|
|
3924
4037
|
catch (error) {
|
|
3925
|
-
|
|
3926
|
-
throw error;
|
|
3927
|
-
}
|
|
4038
|
+
assertsError(error);
|
|
3928
4039
|
if (error instanceof UnexpectedError) {
|
|
3929
4040
|
throw error;
|
|
3930
4041
|
}
|
|
@@ -4545,9 +4656,7 @@
|
|
|
4545
4656
|
await Promise.all(resolving);
|
|
4546
4657
|
}
|
|
4547
4658
|
catch (error /* <- Note: [3] */) {
|
|
4548
|
-
|
|
4549
|
-
throw error;
|
|
4550
|
-
}
|
|
4659
|
+
assertsError(error);
|
|
4551
4660
|
// Note: No need to rethrow UnexpectedError
|
|
4552
4661
|
// if (error instanceof UnexpectedError) {
|
|
4553
4662
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5256,17 +5365,22 @@
|
|
|
5256
5365
|
/**
|
|
5257
5366
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5258
5367
|
*
|
|
5259
|
-
* @
|
|
5368
|
+
* @public exported from `@promptbook/core`
|
|
5260
5369
|
*/
|
|
5261
|
-
const
|
|
5370
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5262
5371
|
try {
|
|
5263
|
-
return await fetch(
|
|
5372
|
+
return await fetch(urlOrRequest, init);
|
|
5264
5373
|
}
|
|
5265
5374
|
catch (error) {
|
|
5266
|
-
|
|
5267
|
-
|
|
5375
|
+
assertsError(error);
|
|
5376
|
+
let url;
|
|
5377
|
+
if (typeof urlOrRequest === 'string') {
|
|
5378
|
+
url = urlOrRequest;
|
|
5379
|
+
}
|
|
5380
|
+
else if (urlOrRequest instanceof Request) {
|
|
5381
|
+
url = urlOrRequest.url;
|
|
5268
5382
|
}
|
|
5269
|
-
throw new
|
|
5383
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
5270
5384
|
Can not fetch "${url}"
|
|
5271
5385
|
|
|
5272
5386
|
Fetch error:
|
|
@@ -5287,7 +5401,7 @@
|
|
|
5287
5401
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5288
5402
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5289
5403
|
var _a;
|
|
5290
|
-
const { fetch =
|
|
5404
|
+
const { fetch = promptbookFetch } = tools;
|
|
5291
5405
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5292
5406
|
let { name } = knowledgeSource;
|
|
5293
5407
|
const { rootDirname = null,
|
|
@@ -5489,9 +5603,7 @@
|
|
|
5489
5603
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5490
5604
|
}
|
|
5491
5605
|
catch (error) {
|
|
5492
|
-
|
|
5493
|
-
throw error;
|
|
5494
|
-
}
|
|
5606
|
+
assertsError(error);
|
|
5495
5607
|
console.warn(error);
|
|
5496
5608
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5497
5609
|
}
|
|
@@ -6289,6 +6401,8 @@
|
|
|
6289
6401
|
*/
|
|
6290
6402
|
|
|
6291
6403
|
/**
|
|
6404
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6405
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6292
6406
|
* Parses the expect command
|
|
6293
6407
|
*
|
|
6294
6408
|
* @see `documentationUrl` for more details
|
|
@@ -6380,9 +6494,7 @@
|
|
|
6380
6494
|
};
|
|
6381
6495
|
}
|
|
6382
6496
|
catch (error) {
|
|
6383
|
-
|
|
6384
|
-
throw error;
|
|
6385
|
-
}
|
|
6497
|
+
assertsError(error);
|
|
6386
6498
|
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
6387
6499
|
Invalid FORMAT command
|
|
6388
6500
|
${block(error.message)}:
|
|
@@ -10167,8 +10279,7 @@
|
|
|
10167
10279
|
options: {
|
|
10168
10280
|
apiKey: 'sk-ant-api03-',
|
|
10169
10281
|
isProxied: true,
|
|
10170
|
-
|
|
10171
|
-
path: DEFAULT_REMOTE_URL_PATH,
|
|
10282
|
+
remoteServerUrl: DEFAULT_REMOTE_SERVER_URL,
|
|
10172
10283
|
},
|
|
10173
10284
|
};
|
|
10174
10285
|
},
|
|
@@ -10477,9 +10588,7 @@
|
|
|
10477
10588
|
return true;
|
|
10478
10589
|
}
|
|
10479
10590
|
catch (error) {
|
|
10480
|
-
|
|
10481
|
-
throw error;
|
|
10482
|
-
}
|
|
10591
|
+
assertsError(error);
|
|
10483
10592
|
return false;
|
|
10484
10593
|
}
|
|
10485
10594
|
}
|
|
@@ -10574,6 +10683,40 @@
|
|
|
10574
10683
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10575
10684
|
*/
|
|
10576
10685
|
|
|
10686
|
+
/**
|
|
10687
|
+
* Convert identification to Promptbook token
|
|
10688
|
+
*
|
|
10689
|
+
* @param identification
|
|
10690
|
+
*
|
|
10691
|
+
* @public exported from `@promptbook/core`
|
|
10692
|
+
*/
|
|
10693
|
+
function identificationToPromptbookToken(identification) {
|
|
10694
|
+
const { appId, userId, userToken } = identification;
|
|
10695
|
+
const promptbookToken = `${appId}-${userId}-${userToken}`;
|
|
10696
|
+
return promptbookToken;
|
|
10697
|
+
}
|
|
10698
|
+
|
|
10699
|
+
/**
|
|
10700
|
+
* Convert Promptbook token to identification
|
|
10701
|
+
*
|
|
10702
|
+
* @param promptbookToken
|
|
10703
|
+
*
|
|
10704
|
+
* @public exported from `@promptbook/core`
|
|
10705
|
+
*/
|
|
10706
|
+
function promptbookTokenToIdentification(promptbookToken) {
|
|
10707
|
+
const [appId, userId, userToken] = promptbookToken.split('-');
|
|
10708
|
+
if (!appId || !userId || !userToken) {
|
|
10709
|
+
throw new Error(`Invalid promptbook token: ${promptbookToken}`);
|
|
10710
|
+
}
|
|
10711
|
+
const identification = {
|
|
10712
|
+
appId,
|
|
10713
|
+
userId,
|
|
10714
|
+
userToken,
|
|
10715
|
+
isAnonymous: false,
|
|
10716
|
+
};
|
|
10717
|
+
return identification;
|
|
10718
|
+
}
|
|
10719
|
+
|
|
10577
10720
|
/**
|
|
10578
10721
|
* Metadata of the scraper
|
|
10579
10722
|
*
|
|
@@ -10870,11 +11013,13 @@
|
|
|
10870
11013
|
exports.ADMIN_EMAIL = ADMIN_EMAIL;
|
|
10871
11014
|
exports.ADMIN_GITHUB_NAME = ADMIN_GITHUB_NAME;
|
|
10872
11015
|
exports.AbstractFormatError = AbstractFormatError;
|
|
11016
|
+
exports.AuthenticationError = AuthenticationError;
|
|
10873
11017
|
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|
|
10874
11018
|
exports.BlackholeStorage = BlackholeStorage;
|
|
10875
11019
|
exports.BoilerplateError = BoilerplateError;
|
|
10876
11020
|
exports.BoilerplateFormfactorDefinition = BoilerplateFormfactorDefinition;
|
|
10877
11021
|
exports.CLAIM = CLAIM;
|
|
11022
|
+
exports.CLI_APP_ID = CLI_APP_ID;
|
|
10878
11023
|
exports.CallbackInterfaceTools = CallbackInterfaceTools;
|
|
10879
11024
|
exports.ChatbotFormfactorDefinition = ChatbotFormfactorDefinition;
|
|
10880
11025
|
exports.CollectionError = CollectionError;
|
|
@@ -10896,8 +11041,7 @@
|
|
|
10896
11041
|
exports.DEFAULT_MAX_PARALLEL_COUNT = DEFAULT_MAX_PARALLEL_COUNT;
|
|
10897
11042
|
exports.DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME;
|
|
10898
11043
|
exports.DEFAULT_PROMPT_TASK_TITLE = DEFAULT_PROMPT_TASK_TITLE;
|
|
10899
|
-
exports.
|
|
10900
|
-
exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
|
|
11044
|
+
exports.DEFAULT_REMOTE_SERVER_URL = DEFAULT_REMOTE_SERVER_URL;
|
|
10901
11045
|
exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;
|
|
10902
11046
|
exports.DEFAULT_TASK_TITLE = DEFAULT_TASK_TITLE;
|
|
10903
11047
|
exports.EXPECTATION_UNITS = EXPECTATION_UNITS;
|
|
@@ -10910,8 +11054,6 @@
|
|
|
10910
11054
|
exports.GenericFormfactorDefinition = GenericFormfactorDefinition;
|
|
10911
11055
|
exports.ImageGeneratorFormfactorDefinition = ImageGeneratorFormfactorDefinition;
|
|
10912
11056
|
exports.KnowledgeScrapeError = KnowledgeScrapeError;
|
|
10913
|
-
exports.LOGO_DARK_SRC = LOGO_DARK_SRC;
|
|
10914
|
-
exports.LOGO_LIGHT_SRC = LOGO_LIGHT_SRC;
|
|
10915
11057
|
exports.LimitReachedError = LimitReachedError;
|
|
10916
11058
|
exports.MANDATORY_CSV_SETTINGS = MANDATORY_CSV_SETTINGS;
|
|
10917
11059
|
exports.MAX_FILENAME_LENGTH = MAX_FILENAME_LENGTH;
|
|
@@ -10925,6 +11067,7 @@
|
|
|
10925
11067
|
exports.NotFoundError = NotFoundError;
|
|
10926
11068
|
exports.NotYetImplementedError = NotYetImplementedError;
|
|
10927
11069
|
exports.ORDER_OF_PIPELINE_JSON = ORDER_OF_PIPELINE_JSON;
|
|
11070
|
+
exports.PLAYGROUND_APP_ID = PLAYGROUND_APP_ID;
|
|
10928
11071
|
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
10929
11072
|
exports.PROMPTBOOK_ERRORS = PROMPTBOOK_ERRORS;
|
|
10930
11073
|
exports.ParseError = ParseError;
|
|
@@ -10932,6 +11075,8 @@
|
|
|
10932
11075
|
exports.PipelineLogicError = PipelineLogicError;
|
|
10933
11076
|
exports.PipelineUrlError = PipelineUrlError;
|
|
10934
11077
|
exports.PrefixStorage = PrefixStorage;
|
|
11078
|
+
exports.PromptbookFetchError = PromptbookFetchError;
|
|
11079
|
+
exports.REMOTE_SERVER_URLS = REMOTE_SERVER_URLS;
|
|
10935
11080
|
exports.RESERVED_PARAMETER_NAMES = RESERVED_PARAMETER_NAMES;
|
|
10936
11081
|
exports.SET_IS_VERBOSE = SET_IS_VERBOSE;
|
|
10937
11082
|
exports.SectionTypes = SectionTypes;
|
|
@@ -10942,6 +11087,7 @@
|
|
|
10942
11087
|
exports.UNCERTAIN_USAGE = UNCERTAIN_USAGE;
|
|
10943
11088
|
exports.UNCERTAIN_ZERO_VALUE = UNCERTAIN_ZERO_VALUE;
|
|
10944
11089
|
exports.UnexpectedError = UnexpectedError;
|
|
11090
|
+
exports.WrappedError = WrappedError;
|
|
10945
11091
|
exports.ZERO_USAGE = ZERO_USAGE;
|
|
10946
11092
|
exports.ZERO_VALUE = ZERO_VALUE;
|
|
10947
11093
|
exports._AnthropicClaudeMetadataRegistration = _AnthropicClaudeMetadataRegistration;
|
|
@@ -10973,6 +11119,7 @@
|
|
|
10973
11119
|
exports.executionReportJsonToString = executionReportJsonToString;
|
|
10974
11120
|
exports.extractParameterNamesFromTask = extractParameterNamesFromTask;
|
|
10975
11121
|
exports.getPipelineInterface = getPipelineInterface;
|
|
11122
|
+
exports.identificationToPromptbookToken = identificationToPromptbookToken;
|
|
10976
11123
|
exports.isPassingExpectations = isPassingExpectations;
|
|
10977
11124
|
exports.isPipelineImplementingInterface = isPipelineImplementingInterface;
|
|
10978
11125
|
exports.isPipelineInterfacesEqual = isPipelineInterfacesEqual;
|
|
@@ -10988,6 +11135,8 @@
|
|
|
10988
11135
|
exports.preparePipeline = preparePipeline;
|
|
10989
11136
|
exports.prepareTasks = prepareTasks;
|
|
10990
11137
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
11138
|
+
exports.promptbookFetch = promptbookFetch;
|
|
11139
|
+
exports.promptbookTokenToIdentification = promptbookTokenToIdentification;
|
|
10991
11140
|
exports.unpreparePipeline = unpreparePipeline;
|
|
10992
11141
|
exports.usageToHuman = usageToHuman;
|
|
10993
11142
|
exports.usageToWorktime = usageToWorktime;
|