@promptbook/legacy-documents 0.89.0-1 → 0.89.0-13
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 +3 -1
- package/esm/index.es.js +224 -111
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +18 -4
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +18 -20
- package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +15 -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 +16 -8
- 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/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +10 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
- package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
- package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
- 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 +36 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
- package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/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 +2 -3
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +89 -4
- 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 +37 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +224 -111
- 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 -64
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/README.md
CHANGED
|
@@ -202,7 +202,7 @@ Each part of the book defines one of 3 circles:
|
|
|
202
202
|
|
|
203
203
|
### **What:** Workflows, Tasks and Parameters
|
|
204
204
|
|
|
205
|
-
What work needs to be done. Each book defines a workflow, which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
|
|
205
|
+
What work needs to be done. Each book defines a [workflow *(scenario or pipeline)*](https://github.com/webgptorg/promptbook/discussions/88), which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
|
|
206
206
|
|
|
207
207
|
**Related commands:**
|
|
208
208
|
|
|
@@ -312,6 +312,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
312
312
|
|
|
313
313
|
|
|
314
314
|
|
|
315
|
+
|
|
316
|
+
|
|
315
317
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
316
318
|
|
|
317
319
|
|
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-13';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -123,6 +123,7 @@ const VALUE_STRINGS = {
|
|
|
123
123
|
infinity: '(infinity; ∞)',
|
|
124
124
|
negativeInfinity: '(negative infinity; -∞)',
|
|
125
125
|
unserializable: '(unserializable value)',
|
|
126
|
+
circular: '(circular JSON)',
|
|
126
127
|
};
|
|
127
128
|
/**
|
|
128
129
|
* Small number limit
|
|
@@ -162,6 +163,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
162
163
|
*/
|
|
163
164
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
164
165
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
166
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
165
167
|
/**
|
|
166
168
|
* Where to store the temporary downloads
|
|
167
169
|
*
|
|
@@ -213,7 +215,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
213
215
|
true);
|
|
214
216
|
/**
|
|
215
217
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
216
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
218
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
217
219
|
*/
|
|
218
220
|
|
|
219
221
|
/**
|
|
@@ -432,6 +434,7 @@ function $execCommand(options) {
|
|
|
432
434
|
}
|
|
433
435
|
else {
|
|
434
436
|
console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
|
|
437
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
435
438
|
resolve('Command exceeded time limit');
|
|
436
439
|
}
|
|
437
440
|
});
|
|
@@ -457,6 +460,7 @@ function $execCommand(options) {
|
|
|
457
460
|
output.push(stderr.toString());
|
|
458
461
|
if (isVerbose && stderr.toString().trim()) {
|
|
459
462
|
console.warn(stderr.toString());
|
|
463
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
460
464
|
}
|
|
461
465
|
});
|
|
462
466
|
const finishWithCode = (code) => {
|
|
@@ -468,6 +472,7 @@ function $execCommand(options) {
|
|
|
468
472
|
else {
|
|
469
473
|
if (isVerbose) {
|
|
470
474
|
console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
|
|
475
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
471
476
|
}
|
|
472
477
|
resolve(spaceTrim(output.join('\n')));
|
|
473
478
|
}
|
|
@@ -489,6 +494,7 @@ function $execCommand(options) {
|
|
|
489
494
|
else {
|
|
490
495
|
if (isVerbose) {
|
|
491
496
|
console.warn(error);
|
|
497
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
492
498
|
}
|
|
493
499
|
resolve(spaceTrim(output.join('\n')));
|
|
494
500
|
}
|
|
@@ -1065,6 +1071,56 @@ class ParseError extends Error {
|
|
|
1065
1071
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1066
1072
|
*/
|
|
1067
1073
|
|
|
1074
|
+
/**
|
|
1075
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
1076
|
+
*
|
|
1077
|
+
* @public exported from `@promptbook/core`
|
|
1078
|
+
*/
|
|
1079
|
+
class WrappedError extends Error {
|
|
1080
|
+
constructor(whatWasThrown) {
|
|
1081
|
+
const tag = `[🤮]`;
|
|
1082
|
+
console.error(tag, whatWasThrown);
|
|
1083
|
+
super(spaceTrim((block) => `
|
|
1084
|
+
${ /* Fixing tests !!! block(valueToString(whatWasThrown)) */block(`non-Error object was thrown`)}
|
|
1085
|
+
|
|
1086
|
+
Note: Look for ${tag} in the console for more details
|
|
1087
|
+
!!! Note: \`WrappedError\` indicates that somewhere in the code non-Error object was thrown and it was wrapped
|
|
1088
|
+
|
|
1089
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
1090
|
+
|
|
1091
|
+
`));
|
|
1092
|
+
this.name = 'WrappedError';
|
|
1093
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* !!!@@@
|
|
1099
|
+
*
|
|
1100
|
+
* @param whatWasThrown !!!@@@
|
|
1101
|
+
* @returns !!!@@@
|
|
1102
|
+
*
|
|
1103
|
+
* @private within the repository
|
|
1104
|
+
*/
|
|
1105
|
+
function assertsError(whatWasThrown) {
|
|
1106
|
+
// Case 1: !!!@@@
|
|
1107
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1108
|
+
const wrappedError = whatWasThrown;
|
|
1109
|
+
throw wrappedError;
|
|
1110
|
+
}
|
|
1111
|
+
// Case 2: !!!@@@
|
|
1112
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1113
|
+
const unexpectedError = whatWasThrown;
|
|
1114
|
+
throw unexpectedError;
|
|
1115
|
+
}
|
|
1116
|
+
// Case 3: !!!@@@
|
|
1117
|
+
if (whatWasThrown instanceof Error) {
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
// Case 4: !!!@@@
|
|
1121
|
+
throw new WrappedError(whatWasThrown);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1068
1124
|
/**
|
|
1069
1125
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1070
1126
|
*
|
|
@@ -1076,9 +1132,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
1076
1132
|
return true;
|
|
1077
1133
|
}
|
|
1078
1134
|
catch (error) {
|
|
1079
|
-
|
|
1080
|
-
throw error;
|
|
1081
|
-
}
|
|
1135
|
+
assertsError(error);
|
|
1082
1136
|
if (error.message.includes('Unexpected token')) {
|
|
1083
1137
|
return false;
|
|
1084
1138
|
}
|
|
@@ -1431,9 +1485,7 @@ function checkSerializableAsJson(options) {
|
|
|
1431
1485
|
JSON.stringify(value); // <- TODO: [0]
|
|
1432
1486
|
}
|
|
1433
1487
|
catch (error) {
|
|
1434
|
-
|
|
1435
|
-
throw error;
|
|
1436
|
-
}
|
|
1488
|
+
assertsError(error);
|
|
1437
1489
|
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1438
1490
|
\`${name}\` is not serializable
|
|
1439
1491
|
|
|
@@ -2304,6 +2356,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
2304
2356
|
}
|
|
2305
2357
|
}
|
|
2306
2358
|
|
|
2359
|
+
/**
|
|
2360
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
2361
|
+
*
|
|
2362
|
+
* @public exported from `@promptbook/core`
|
|
2363
|
+
*/
|
|
2364
|
+
class AuthenticationError extends Error {
|
|
2365
|
+
constructor(message) {
|
|
2366
|
+
super(message);
|
|
2367
|
+
this.name = 'AuthenticationError';
|
|
2368
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2307
2372
|
/**
|
|
2308
2373
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2309
2374
|
*
|
|
@@ -2369,6 +2434,19 @@ class NotYetImplementedError extends Error {
|
|
|
2369
2434
|
}
|
|
2370
2435
|
}
|
|
2371
2436
|
|
|
2437
|
+
/**
|
|
2438
|
+
* Error thrown when a fetch request fails
|
|
2439
|
+
*
|
|
2440
|
+
* @public exported from `@promptbook/core`
|
|
2441
|
+
*/
|
|
2442
|
+
class PromptbookFetchError extends Error {
|
|
2443
|
+
constructor(message) {
|
|
2444
|
+
super(message);
|
|
2445
|
+
this.name = 'PromptbookFetchError';
|
|
2446
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2372
2450
|
/**
|
|
2373
2451
|
* Index of all custom errors
|
|
2374
2452
|
*
|
|
@@ -2389,7 +2467,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2389
2467
|
PipelineExecutionError,
|
|
2390
2468
|
PipelineLogicError,
|
|
2391
2469
|
PipelineUrlError,
|
|
2470
|
+
AuthenticationError,
|
|
2471
|
+
PromptbookFetchError,
|
|
2392
2472
|
UnexpectedError,
|
|
2473
|
+
WrappedError,
|
|
2393
2474
|
// TODO: [🪑]> VersionMismatchError,
|
|
2394
2475
|
};
|
|
2395
2476
|
/**
|
|
@@ -2467,6 +2548,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2467
2548
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2468
2549
|
for (const warning of warnings) {
|
|
2469
2550
|
console.warn(warning.message);
|
|
2551
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2470
2552
|
}
|
|
2471
2553
|
if (isSuccessful === true) {
|
|
2472
2554
|
return;
|
|
@@ -2538,6 +2620,7 @@ function createTask(options) {
|
|
|
2538
2620
|
partialResultSubject.next(executionResult);
|
|
2539
2621
|
}
|
|
2540
2622
|
catch (error) {
|
|
2623
|
+
assertsError(error);
|
|
2541
2624
|
status = 'ERROR';
|
|
2542
2625
|
errors.push(error);
|
|
2543
2626
|
partialResultSubject.error(error);
|
|
@@ -2604,6 +2687,10 @@ function serializeError(error) {
|
|
|
2604
2687
|
|
|
2605
2688
|
Cannot serialize error with name "${name}"
|
|
2606
2689
|
|
|
2690
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2691
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2692
|
+
|
|
2693
|
+
|
|
2607
2694
|
${block(stack || message)}
|
|
2608
2695
|
|
|
2609
2696
|
`));
|
|
@@ -2645,30 +2732,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2645
2732
|
await Promise.all(tasks);
|
|
2646
2733
|
}
|
|
2647
2734
|
|
|
2735
|
+
/**
|
|
2736
|
+
* Represents the uncertain value
|
|
2737
|
+
*
|
|
2738
|
+
* @public exported from `@promptbook/core`
|
|
2739
|
+
*/
|
|
2740
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2741
|
+
/**
|
|
2742
|
+
* Represents the uncertain value
|
|
2743
|
+
*
|
|
2744
|
+
* @public exported from `@promptbook/core`
|
|
2745
|
+
*/
|
|
2746
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2648
2747
|
/**
|
|
2649
2748
|
* Represents the usage with no resources consumed
|
|
2650
2749
|
*
|
|
2651
2750
|
* @public exported from `@promptbook/core`
|
|
2652
2751
|
*/
|
|
2653
2752
|
const ZERO_USAGE = $deepFreeze({
|
|
2654
|
-
price:
|
|
2753
|
+
price: ZERO_VALUE,
|
|
2655
2754
|
input: {
|
|
2656
|
-
tokensCount:
|
|
2657
|
-
charactersCount:
|
|
2658
|
-
wordsCount:
|
|
2659
|
-
sentencesCount:
|
|
2660
|
-
linesCount:
|
|
2661
|
-
paragraphsCount:
|
|
2662
|
-
pagesCount:
|
|
2755
|
+
tokensCount: ZERO_VALUE,
|
|
2756
|
+
charactersCount: ZERO_VALUE,
|
|
2757
|
+
wordsCount: ZERO_VALUE,
|
|
2758
|
+
sentencesCount: ZERO_VALUE,
|
|
2759
|
+
linesCount: ZERO_VALUE,
|
|
2760
|
+
paragraphsCount: ZERO_VALUE,
|
|
2761
|
+
pagesCount: ZERO_VALUE,
|
|
2663
2762
|
},
|
|
2664
2763
|
output: {
|
|
2665
|
-
tokensCount:
|
|
2666
|
-
charactersCount:
|
|
2667
|
-
wordsCount:
|
|
2668
|
-
sentencesCount:
|
|
2669
|
-
linesCount:
|
|
2670
|
-
paragraphsCount:
|
|
2671
|
-
pagesCount:
|
|
2764
|
+
tokensCount: ZERO_VALUE,
|
|
2765
|
+
charactersCount: ZERO_VALUE,
|
|
2766
|
+
wordsCount: ZERO_VALUE,
|
|
2767
|
+
sentencesCount: ZERO_VALUE,
|
|
2768
|
+
linesCount: ZERO_VALUE,
|
|
2769
|
+
paragraphsCount: ZERO_VALUE,
|
|
2770
|
+
pagesCount: ZERO_VALUE,
|
|
2672
2771
|
},
|
|
2673
2772
|
});
|
|
2674
2773
|
/**
|
|
@@ -2677,24 +2776,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2677
2776
|
* @public exported from `@promptbook/core`
|
|
2678
2777
|
*/
|
|
2679
2778
|
$deepFreeze({
|
|
2680
|
-
price:
|
|
2779
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2681
2780
|
input: {
|
|
2682
|
-
tokensCount:
|
|
2683
|
-
charactersCount:
|
|
2684
|
-
wordsCount:
|
|
2685
|
-
sentencesCount:
|
|
2686
|
-
linesCount:
|
|
2687
|
-
paragraphsCount:
|
|
2688
|
-
pagesCount:
|
|
2781
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2782
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2783
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2784
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2785
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2786
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2787
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2689
2788
|
},
|
|
2690
2789
|
output: {
|
|
2691
|
-
tokensCount:
|
|
2692
|
-
charactersCount:
|
|
2693
|
-
wordsCount:
|
|
2694
|
-
sentencesCount:
|
|
2695
|
-
linesCount:
|
|
2696
|
-
paragraphsCount:
|
|
2697
|
-
pagesCount:
|
|
2790
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2791
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2792
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2793
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2794
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2795
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2796
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2698
2797
|
},
|
|
2699
2798
|
});
|
|
2700
2799
|
/**
|
|
@@ -2913,14 +3012,15 @@ class MultipleLlmExecutionTools {
|
|
|
2913
3012
|
}
|
|
2914
3013
|
}
|
|
2915
3014
|
catch (error) {
|
|
2916
|
-
|
|
3015
|
+
assertsError(error);
|
|
3016
|
+
if (error instanceof UnexpectedError) {
|
|
2917
3017
|
throw error;
|
|
2918
3018
|
}
|
|
2919
3019
|
errors.push({ llmExecutionTools, error });
|
|
2920
3020
|
}
|
|
2921
3021
|
}
|
|
2922
3022
|
if (errors.length === 1) {
|
|
2923
|
-
throw errors[0];
|
|
3023
|
+
throw errors[0].error;
|
|
2924
3024
|
}
|
|
2925
3025
|
else if (errors.length > 1) {
|
|
2926
3026
|
throw new PipelineExecutionError(
|
|
@@ -2982,6 +3082,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2982
3082
|
`);
|
|
2983
3083
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2984
3084
|
console.warn(warningMessage);
|
|
3085
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2985
3086
|
/*
|
|
2986
3087
|
return {
|
|
2987
3088
|
async listModels() {
|
|
@@ -3357,17 +3458,22 @@ function mimeTypeToExtension(value) {
|
|
|
3357
3458
|
/**
|
|
3358
3459
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3359
3460
|
*
|
|
3360
|
-
* @
|
|
3461
|
+
* @public exported from `@promptbook/core`
|
|
3361
3462
|
*/
|
|
3362
|
-
const
|
|
3463
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3363
3464
|
try {
|
|
3364
|
-
return await fetch(
|
|
3465
|
+
return await fetch(urlOrRequest, init);
|
|
3365
3466
|
}
|
|
3366
3467
|
catch (error) {
|
|
3367
|
-
|
|
3368
|
-
|
|
3468
|
+
assertsError(error);
|
|
3469
|
+
let url;
|
|
3470
|
+
if (typeof urlOrRequest === 'string') {
|
|
3471
|
+
url = urlOrRequest;
|
|
3472
|
+
}
|
|
3473
|
+
else if (urlOrRequest instanceof Request) {
|
|
3474
|
+
url = urlOrRequest.url;
|
|
3369
3475
|
}
|
|
3370
|
-
throw new
|
|
3476
|
+
throw new PromptbookFetchError(spaceTrim$1((block) => `
|
|
3371
3477
|
Can not fetch "${url}"
|
|
3372
3478
|
|
|
3373
3479
|
Fetch error:
|
|
@@ -3388,7 +3494,7 @@ const scraperFetch = async (url, init) => {
|
|
|
3388
3494
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3389
3495
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3390
3496
|
var _a;
|
|
3391
|
-
const { fetch =
|
|
3497
|
+
const { fetch = promptbookFetch } = tools;
|
|
3392
3498
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3393
3499
|
let { name } = knowledgeSource;
|
|
3394
3500
|
const { rootDirname = null,
|
|
@@ -3529,63 +3635,71 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3529
3635
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3530
3636
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3531
3637
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3638
|
+
try {
|
|
3639
|
+
let partialPieces = null;
|
|
3640
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3641
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3642
|
+
for (const scraper of scrapers) {
|
|
3643
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3644
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3645
|
+
) {
|
|
3646
|
+
continue;
|
|
3647
|
+
}
|
|
3648
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3649
|
+
if (partialPiecesUnchecked !== null) {
|
|
3650
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3651
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3652
|
+
break;
|
|
3653
|
+
}
|
|
3654
|
+
console.warn(spaceTrim$1((block) => `
|
|
3655
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3549
3656
|
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3657
|
+
The source:
|
|
3658
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3659
|
+
.split('\n')
|
|
3660
|
+
.map((line) => `> ${line}`)
|
|
3661
|
+
.join('\n'))}
|
|
3555
3662
|
|
|
3556
|
-
|
|
3663
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3557
3664
|
|
|
3558
3665
|
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3666
|
+
`));
|
|
3667
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3668
|
+
}
|
|
3669
|
+
if (partialPieces === null) {
|
|
3670
|
+
throw new KnowledgeScrapeError(spaceTrim$1((block) => `
|
|
3671
|
+
Cannot scrape knowledge
|
|
3564
3672
|
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3673
|
+
The source:
|
|
3674
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3675
|
+
.split('\n')
|
|
3676
|
+
.map((line) => `> ${line}`)
|
|
3677
|
+
.join('\n'))}
|
|
3570
3678
|
|
|
3571
|
-
|
|
3679
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3572
3680
|
|
|
3573
|
-
|
|
3681
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3574
3682
|
|
|
3575
3683
|
|
|
3576
|
-
|
|
3684
|
+
`));
|
|
3685
|
+
}
|
|
3686
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3687
|
+
...partialPiece,
|
|
3688
|
+
sources: [
|
|
3689
|
+
{
|
|
3690
|
+
name: knowledgeSource.name,
|
|
3691
|
+
// line, column <- TODO: [☀]
|
|
3692
|
+
// <- TODO: [❎]
|
|
3693
|
+
},
|
|
3694
|
+
],
|
|
3695
|
+
}));
|
|
3696
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3697
|
+
}
|
|
3698
|
+
catch (error) {
|
|
3699
|
+
assertsError(error);
|
|
3700
|
+
console.warn(error);
|
|
3701
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3577
3702
|
}
|
|
3578
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3579
|
-
...partialPiece,
|
|
3580
|
-
sources: [
|
|
3581
|
-
{
|
|
3582
|
-
name: knowledgeSource.name,
|
|
3583
|
-
// line, column <- TODO: [☀]
|
|
3584
|
-
// <- TODO: [❎]
|
|
3585
|
-
},
|
|
3586
|
-
],
|
|
3587
|
-
}));
|
|
3588
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3589
3703
|
});
|
|
3590
3704
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3591
3705
|
return knowledgePrepared;
|
|
@@ -3874,13 +3988,19 @@ function valueToString(value) {
|
|
|
3874
3988
|
return value.toISOString();
|
|
3875
3989
|
}
|
|
3876
3990
|
else {
|
|
3877
|
-
|
|
3991
|
+
try {
|
|
3992
|
+
return JSON.stringify(value);
|
|
3993
|
+
}
|
|
3994
|
+
catch (error) {
|
|
3995
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3996
|
+
return VALUE_STRINGS.circular;
|
|
3997
|
+
}
|
|
3998
|
+
throw error;
|
|
3999
|
+
}
|
|
3878
4000
|
}
|
|
3879
4001
|
}
|
|
3880
4002
|
catch (error) {
|
|
3881
|
-
|
|
3882
|
-
throw error;
|
|
3883
|
-
}
|
|
4003
|
+
assertsError(error);
|
|
3884
4004
|
console.error(error);
|
|
3885
4005
|
return VALUE_STRINGS.unserializable;
|
|
3886
4006
|
}
|
|
@@ -3937,9 +4057,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
3937
4057
|
}
|
|
3938
4058
|
}
|
|
3939
4059
|
catch (error) {
|
|
3940
|
-
|
|
3941
|
-
throw error;
|
|
3942
|
-
}
|
|
4060
|
+
assertsError(error);
|
|
3943
4061
|
throw new ParseError(spaceTrim((block) => `
|
|
3944
4062
|
Can not extract variables from the script
|
|
3945
4063
|
${block(error.stack || error.message)}
|
|
@@ -4003,7 +4121,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
4003
4121
|
if (parameterNames.has(subparameterName)) {
|
|
4004
4122
|
parameterNames.delete(subparameterName);
|
|
4005
4123
|
parameterNames.add(foreach.parameterName);
|
|
4006
|
-
// <- TODO: [
|
|
4124
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
4007
4125
|
}
|
|
4008
4126
|
}
|
|
4009
4127
|
}
|
|
@@ -4804,9 +4922,7 @@ async function executeAttempts(options) {
|
|
|
4804
4922
|
break scripts;
|
|
4805
4923
|
}
|
|
4806
4924
|
catch (error) {
|
|
4807
|
-
|
|
4808
|
-
throw error;
|
|
4809
|
-
}
|
|
4925
|
+
assertsError(error);
|
|
4810
4926
|
if (error instanceof UnexpectedError) {
|
|
4811
4927
|
throw error;
|
|
4812
4928
|
}
|
|
@@ -4876,9 +4992,7 @@ async function executeAttempts(options) {
|
|
|
4876
4992
|
break scripts;
|
|
4877
4993
|
}
|
|
4878
4994
|
catch (error) {
|
|
4879
|
-
|
|
4880
|
-
throw error;
|
|
4881
|
-
}
|
|
4995
|
+
assertsError(error);
|
|
4882
4996
|
if (error instanceof UnexpectedError) {
|
|
4883
4997
|
throw error;
|
|
4884
4998
|
}
|
|
@@ -5499,9 +5613,7 @@ async function executePipeline(options) {
|
|
|
5499
5613
|
await Promise.all(resolving);
|
|
5500
5614
|
}
|
|
5501
5615
|
catch (error /* <- Note: [3] */) {
|
|
5502
|
-
|
|
5503
|
-
throw error;
|
|
5504
|
-
}
|
|
5616
|
+
assertsError(error);
|
|
5505
5617
|
// Note: No need to rethrow UnexpectedError
|
|
5506
5618
|
// if (error instanceof UnexpectedError) {
|
|
5507
5619
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5599,6 +5711,7 @@ function createPipelineExecutor(options) {
|
|
|
5599
5711
|
|
|
5600
5712
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5601
5713
|
`));
|
|
5714
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5602
5715
|
}
|
|
5603
5716
|
let runCount = 0;
|
|
5604
5717
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|