@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/umd/index.umd.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-13';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -121,6 +121,7 @@
|
|
|
121
121
|
infinity: '(infinity; ∞)',
|
|
122
122
|
negativeInfinity: '(negative infinity; -∞)',
|
|
123
123
|
unserializable: '(unserializable value)',
|
|
124
|
+
circular: '(circular JSON)',
|
|
124
125
|
};
|
|
125
126
|
/**
|
|
126
127
|
* Small number limit
|
|
@@ -160,6 +161,7 @@
|
|
|
160
161
|
*/
|
|
161
162
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
162
163
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
164
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
163
165
|
/**
|
|
164
166
|
* Where to store the temporary downloads
|
|
165
167
|
*
|
|
@@ -211,7 +213,7 @@
|
|
|
211
213
|
true);
|
|
212
214
|
/**
|
|
213
215
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
214
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
216
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
215
217
|
*/
|
|
216
218
|
|
|
217
219
|
/**
|
|
@@ -430,6 +432,7 @@
|
|
|
430
432
|
}
|
|
431
433
|
else {
|
|
432
434
|
console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
|
|
435
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
433
436
|
resolve('Command exceeded time limit');
|
|
434
437
|
}
|
|
435
438
|
});
|
|
@@ -455,6 +458,7 @@
|
|
|
455
458
|
output.push(stderr.toString());
|
|
456
459
|
if (isVerbose && stderr.toString().trim()) {
|
|
457
460
|
console.warn(stderr.toString());
|
|
461
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
458
462
|
}
|
|
459
463
|
});
|
|
460
464
|
const finishWithCode = (code) => {
|
|
@@ -466,6 +470,7 @@
|
|
|
466
470
|
else {
|
|
467
471
|
if (isVerbose) {
|
|
468
472
|
console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
|
|
473
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
469
474
|
}
|
|
470
475
|
resolve(spaceTrim.spaceTrim(output.join('\n')));
|
|
471
476
|
}
|
|
@@ -487,6 +492,7 @@
|
|
|
487
492
|
else {
|
|
488
493
|
if (isVerbose) {
|
|
489
494
|
console.warn(error);
|
|
495
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
490
496
|
}
|
|
491
497
|
resolve(spaceTrim.spaceTrim(output.join('\n')));
|
|
492
498
|
}
|
|
@@ -1063,6 +1069,56 @@
|
|
|
1063
1069
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1064
1070
|
*/
|
|
1065
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
1074
|
+
*
|
|
1075
|
+
* @public exported from `@promptbook/core`
|
|
1076
|
+
*/
|
|
1077
|
+
class WrappedError extends Error {
|
|
1078
|
+
constructor(whatWasThrown) {
|
|
1079
|
+
const tag = `[🤮]`;
|
|
1080
|
+
console.error(tag, whatWasThrown);
|
|
1081
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
1082
|
+
${ /* Fixing tests !!! block(valueToString(whatWasThrown)) */block(`non-Error object was thrown`)}
|
|
1083
|
+
|
|
1084
|
+
Note: Look for ${tag} in the console for more details
|
|
1085
|
+
!!! Note: \`WrappedError\` indicates that somewhere in the code non-Error object was thrown and it was wrapped
|
|
1086
|
+
|
|
1087
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
1088
|
+
|
|
1089
|
+
`));
|
|
1090
|
+
this.name = 'WrappedError';
|
|
1091
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* !!!@@@
|
|
1097
|
+
*
|
|
1098
|
+
* @param whatWasThrown !!!@@@
|
|
1099
|
+
* @returns !!!@@@
|
|
1100
|
+
*
|
|
1101
|
+
* @private within the repository
|
|
1102
|
+
*/
|
|
1103
|
+
function assertsError(whatWasThrown) {
|
|
1104
|
+
// Case 1: !!!@@@
|
|
1105
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1106
|
+
const wrappedError = whatWasThrown;
|
|
1107
|
+
throw wrappedError;
|
|
1108
|
+
}
|
|
1109
|
+
// Case 2: !!!@@@
|
|
1110
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1111
|
+
const unexpectedError = whatWasThrown;
|
|
1112
|
+
throw unexpectedError;
|
|
1113
|
+
}
|
|
1114
|
+
// Case 3: !!!@@@
|
|
1115
|
+
if (whatWasThrown instanceof Error) {
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
// Case 4: !!!@@@
|
|
1119
|
+
throw new WrappedError(whatWasThrown);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1066
1122
|
/**
|
|
1067
1123
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1068
1124
|
*
|
|
@@ -1074,9 +1130,7 @@
|
|
|
1074
1130
|
return true;
|
|
1075
1131
|
}
|
|
1076
1132
|
catch (error) {
|
|
1077
|
-
|
|
1078
|
-
throw error;
|
|
1079
|
-
}
|
|
1133
|
+
assertsError(error);
|
|
1080
1134
|
if (error.message.includes('Unexpected token')) {
|
|
1081
1135
|
return false;
|
|
1082
1136
|
}
|
|
@@ -1429,9 +1483,7 @@
|
|
|
1429
1483
|
JSON.stringify(value); // <- TODO: [0]
|
|
1430
1484
|
}
|
|
1431
1485
|
catch (error) {
|
|
1432
|
-
|
|
1433
|
-
throw error;
|
|
1434
|
-
}
|
|
1486
|
+
assertsError(error);
|
|
1435
1487
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
1436
1488
|
\`${name}\` is not serializable
|
|
1437
1489
|
|
|
@@ -2302,6 +2354,19 @@
|
|
|
2302
2354
|
}
|
|
2303
2355
|
}
|
|
2304
2356
|
|
|
2357
|
+
/**
|
|
2358
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
2359
|
+
*
|
|
2360
|
+
* @public exported from `@promptbook/core`
|
|
2361
|
+
*/
|
|
2362
|
+
class AuthenticationError extends Error {
|
|
2363
|
+
constructor(message) {
|
|
2364
|
+
super(message);
|
|
2365
|
+
this.name = 'AuthenticationError';
|
|
2366
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2305
2370
|
/**
|
|
2306
2371
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2307
2372
|
*
|
|
@@ -2367,6 +2432,19 @@
|
|
|
2367
2432
|
}
|
|
2368
2433
|
}
|
|
2369
2434
|
|
|
2435
|
+
/**
|
|
2436
|
+
* Error thrown when a fetch request fails
|
|
2437
|
+
*
|
|
2438
|
+
* @public exported from `@promptbook/core`
|
|
2439
|
+
*/
|
|
2440
|
+
class PromptbookFetchError extends Error {
|
|
2441
|
+
constructor(message) {
|
|
2442
|
+
super(message);
|
|
2443
|
+
this.name = 'PromptbookFetchError';
|
|
2444
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2370
2448
|
/**
|
|
2371
2449
|
* Index of all custom errors
|
|
2372
2450
|
*
|
|
@@ -2387,7 +2465,10 @@
|
|
|
2387
2465
|
PipelineExecutionError,
|
|
2388
2466
|
PipelineLogicError,
|
|
2389
2467
|
PipelineUrlError,
|
|
2468
|
+
AuthenticationError,
|
|
2469
|
+
PromptbookFetchError,
|
|
2390
2470
|
UnexpectedError,
|
|
2471
|
+
WrappedError,
|
|
2391
2472
|
// TODO: [🪑]> VersionMismatchError,
|
|
2392
2473
|
};
|
|
2393
2474
|
/**
|
|
@@ -2465,6 +2546,7 @@
|
|
|
2465
2546
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2466
2547
|
for (const warning of warnings) {
|
|
2467
2548
|
console.warn(warning.message);
|
|
2549
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2468
2550
|
}
|
|
2469
2551
|
if (isSuccessful === true) {
|
|
2470
2552
|
return;
|
|
@@ -2536,6 +2618,7 @@
|
|
|
2536
2618
|
partialResultSubject.next(executionResult);
|
|
2537
2619
|
}
|
|
2538
2620
|
catch (error) {
|
|
2621
|
+
assertsError(error);
|
|
2539
2622
|
status = 'ERROR';
|
|
2540
2623
|
errors.push(error);
|
|
2541
2624
|
partialResultSubject.error(error);
|
|
@@ -2602,6 +2685,10 @@
|
|
|
2602
2685
|
|
|
2603
2686
|
Cannot serialize error with name "${name}"
|
|
2604
2687
|
|
|
2688
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2689
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2690
|
+
|
|
2691
|
+
|
|
2605
2692
|
${block(stack || message)}
|
|
2606
2693
|
|
|
2607
2694
|
`));
|
|
@@ -2643,30 +2730,42 @@
|
|
|
2643
2730
|
await Promise.all(tasks);
|
|
2644
2731
|
}
|
|
2645
2732
|
|
|
2733
|
+
/**
|
|
2734
|
+
* Represents the uncertain value
|
|
2735
|
+
*
|
|
2736
|
+
* @public exported from `@promptbook/core`
|
|
2737
|
+
*/
|
|
2738
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2739
|
+
/**
|
|
2740
|
+
* Represents the uncertain value
|
|
2741
|
+
*
|
|
2742
|
+
* @public exported from `@promptbook/core`
|
|
2743
|
+
*/
|
|
2744
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2646
2745
|
/**
|
|
2647
2746
|
* Represents the usage with no resources consumed
|
|
2648
2747
|
*
|
|
2649
2748
|
* @public exported from `@promptbook/core`
|
|
2650
2749
|
*/
|
|
2651
2750
|
const ZERO_USAGE = $deepFreeze({
|
|
2652
|
-
price:
|
|
2751
|
+
price: ZERO_VALUE,
|
|
2653
2752
|
input: {
|
|
2654
|
-
tokensCount:
|
|
2655
|
-
charactersCount:
|
|
2656
|
-
wordsCount:
|
|
2657
|
-
sentencesCount:
|
|
2658
|
-
linesCount:
|
|
2659
|
-
paragraphsCount:
|
|
2660
|
-
pagesCount:
|
|
2753
|
+
tokensCount: ZERO_VALUE,
|
|
2754
|
+
charactersCount: ZERO_VALUE,
|
|
2755
|
+
wordsCount: ZERO_VALUE,
|
|
2756
|
+
sentencesCount: ZERO_VALUE,
|
|
2757
|
+
linesCount: ZERO_VALUE,
|
|
2758
|
+
paragraphsCount: ZERO_VALUE,
|
|
2759
|
+
pagesCount: ZERO_VALUE,
|
|
2661
2760
|
},
|
|
2662
2761
|
output: {
|
|
2663
|
-
tokensCount:
|
|
2664
|
-
charactersCount:
|
|
2665
|
-
wordsCount:
|
|
2666
|
-
sentencesCount:
|
|
2667
|
-
linesCount:
|
|
2668
|
-
paragraphsCount:
|
|
2669
|
-
pagesCount:
|
|
2762
|
+
tokensCount: ZERO_VALUE,
|
|
2763
|
+
charactersCount: ZERO_VALUE,
|
|
2764
|
+
wordsCount: ZERO_VALUE,
|
|
2765
|
+
sentencesCount: ZERO_VALUE,
|
|
2766
|
+
linesCount: ZERO_VALUE,
|
|
2767
|
+
paragraphsCount: ZERO_VALUE,
|
|
2768
|
+
pagesCount: ZERO_VALUE,
|
|
2670
2769
|
},
|
|
2671
2770
|
});
|
|
2672
2771
|
/**
|
|
@@ -2675,24 +2774,24 @@
|
|
|
2675
2774
|
* @public exported from `@promptbook/core`
|
|
2676
2775
|
*/
|
|
2677
2776
|
$deepFreeze({
|
|
2678
|
-
price:
|
|
2777
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2679
2778
|
input: {
|
|
2680
|
-
tokensCount:
|
|
2681
|
-
charactersCount:
|
|
2682
|
-
wordsCount:
|
|
2683
|
-
sentencesCount:
|
|
2684
|
-
linesCount:
|
|
2685
|
-
paragraphsCount:
|
|
2686
|
-
pagesCount:
|
|
2779
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2780
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2781
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2782
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2783
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2784
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2785
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2687
2786
|
},
|
|
2688
2787
|
output: {
|
|
2689
|
-
tokensCount:
|
|
2690
|
-
charactersCount:
|
|
2691
|
-
wordsCount:
|
|
2692
|
-
sentencesCount:
|
|
2693
|
-
linesCount:
|
|
2694
|
-
paragraphsCount:
|
|
2695
|
-
pagesCount:
|
|
2788
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2789
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2790
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2791
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2792
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2793
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2794
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2696
2795
|
},
|
|
2697
2796
|
});
|
|
2698
2797
|
/**
|
|
@@ -2911,14 +3010,15 @@
|
|
|
2911
3010
|
}
|
|
2912
3011
|
}
|
|
2913
3012
|
catch (error) {
|
|
2914
|
-
|
|
3013
|
+
assertsError(error);
|
|
3014
|
+
if (error instanceof UnexpectedError) {
|
|
2915
3015
|
throw error;
|
|
2916
3016
|
}
|
|
2917
3017
|
errors.push({ llmExecutionTools, error });
|
|
2918
3018
|
}
|
|
2919
3019
|
}
|
|
2920
3020
|
if (errors.length === 1) {
|
|
2921
|
-
throw errors[0];
|
|
3021
|
+
throw errors[0].error;
|
|
2922
3022
|
}
|
|
2923
3023
|
else if (errors.length > 1) {
|
|
2924
3024
|
throw new PipelineExecutionError(
|
|
@@ -2980,6 +3080,7 @@
|
|
|
2980
3080
|
`);
|
|
2981
3081
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2982
3082
|
console.warn(warningMessage);
|
|
3083
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2983
3084
|
/*
|
|
2984
3085
|
return {
|
|
2985
3086
|
async listModels() {
|
|
@@ -3355,17 +3456,22 @@
|
|
|
3355
3456
|
/**
|
|
3356
3457
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3357
3458
|
*
|
|
3358
|
-
* @
|
|
3459
|
+
* @public exported from `@promptbook/core`
|
|
3359
3460
|
*/
|
|
3360
|
-
const
|
|
3461
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3361
3462
|
try {
|
|
3362
|
-
return await fetch(
|
|
3463
|
+
return await fetch(urlOrRequest, init);
|
|
3363
3464
|
}
|
|
3364
3465
|
catch (error) {
|
|
3365
|
-
|
|
3366
|
-
|
|
3466
|
+
assertsError(error);
|
|
3467
|
+
let url;
|
|
3468
|
+
if (typeof urlOrRequest === 'string') {
|
|
3469
|
+
url = urlOrRequest;
|
|
3367
3470
|
}
|
|
3368
|
-
|
|
3471
|
+
else if (urlOrRequest instanceof Request) {
|
|
3472
|
+
url = urlOrRequest.url;
|
|
3473
|
+
}
|
|
3474
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
3369
3475
|
Can not fetch "${url}"
|
|
3370
3476
|
|
|
3371
3477
|
Fetch error:
|
|
@@ -3386,7 +3492,7 @@
|
|
|
3386
3492
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3387
3493
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3388
3494
|
var _a;
|
|
3389
|
-
const { fetch =
|
|
3495
|
+
const { fetch = promptbookFetch } = tools;
|
|
3390
3496
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3391
3497
|
let { name } = knowledgeSource;
|
|
3392
3498
|
const { rootDirname = null,
|
|
@@ -3527,63 +3633,71 @@
|
|
|
3527
3633
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3528
3634
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3529
3635
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3636
|
+
try {
|
|
3637
|
+
let partialPieces = null;
|
|
3638
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3639
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3640
|
+
for (const scraper of scrapers) {
|
|
3641
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3642
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3643
|
+
) {
|
|
3644
|
+
continue;
|
|
3645
|
+
}
|
|
3646
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3647
|
+
if (partialPiecesUnchecked !== null) {
|
|
3648
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3649
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3650
|
+
break;
|
|
3651
|
+
}
|
|
3652
|
+
console.warn(spaceTrim__default["default"]((block) => `
|
|
3653
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3547
3654
|
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3655
|
+
The source:
|
|
3656
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3657
|
+
.split('\n')
|
|
3658
|
+
.map((line) => `> ${line}`)
|
|
3659
|
+
.join('\n'))}
|
|
3553
3660
|
|
|
3554
|
-
|
|
3661
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3555
3662
|
|
|
3556
3663
|
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3664
|
+
`));
|
|
3665
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3666
|
+
}
|
|
3667
|
+
if (partialPieces === null) {
|
|
3668
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
|
|
3669
|
+
Cannot scrape knowledge
|
|
3562
3670
|
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3671
|
+
The source:
|
|
3672
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3673
|
+
.split('\n')
|
|
3674
|
+
.map((line) => `> ${line}`)
|
|
3675
|
+
.join('\n'))}
|
|
3568
3676
|
|
|
3569
|
-
|
|
3677
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3570
3678
|
|
|
3571
|
-
|
|
3679
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3572
3680
|
|
|
3573
3681
|
|
|
3574
|
-
|
|
3682
|
+
`));
|
|
3683
|
+
}
|
|
3684
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3685
|
+
...partialPiece,
|
|
3686
|
+
sources: [
|
|
3687
|
+
{
|
|
3688
|
+
name: knowledgeSource.name,
|
|
3689
|
+
// line, column <- TODO: [☀]
|
|
3690
|
+
// <- TODO: [❎]
|
|
3691
|
+
},
|
|
3692
|
+
],
|
|
3693
|
+
}));
|
|
3694
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3695
|
+
}
|
|
3696
|
+
catch (error) {
|
|
3697
|
+
assertsError(error);
|
|
3698
|
+
console.warn(error);
|
|
3699
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3575
3700
|
}
|
|
3576
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3577
|
-
...partialPiece,
|
|
3578
|
-
sources: [
|
|
3579
|
-
{
|
|
3580
|
-
name: knowledgeSource.name,
|
|
3581
|
-
// line, column <- TODO: [☀]
|
|
3582
|
-
// <- TODO: [❎]
|
|
3583
|
-
},
|
|
3584
|
-
],
|
|
3585
|
-
}));
|
|
3586
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3587
3701
|
});
|
|
3588
3702
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3589
3703
|
return knowledgePrepared;
|
|
@@ -3872,13 +3986,19 @@
|
|
|
3872
3986
|
return value.toISOString();
|
|
3873
3987
|
}
|
|
3874
3988
|
else {
|
|
3875
|
-
|
|
3989
|
+
try {
|
|
3990
|
+
return JSON.stringify(value);
|
|
3991
|
+
}
|
|
3992
|
+
catch (error) {
|
|
3993
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3994
|
+
return VALUE_STRINGS.circular;
|
|
3995
|
+
}
|
|
3996
|
+
throw error;
|
|
3997
|
+
}
|
|
3876
3998
|
}
|
|
3877
3999
|
}
|
|
3878
4000
|
catch (error) {
|
|
3879
|
-
|
|
3880
|
-
throw error;
|
|
3881
|
-
}
|
|
4001
|
+
assertsError(error);
|
|
3882
4002
|
console.error(error);
|
|
3883
4003
|
return VALUE_STRINGS.unserializable;
|
|
3884
4004
|
}
|
|
@@ -3935,9 +4055,7 @@
|
|
|
3935
4055
|
}
|
|
3936
4056
|
}
|
|
3937
4057
|
catch (error) {
|
|
3938
|
-
|
|
3939
|
-
throw error;
|
|
3940
|
-
}
|
|
4058
|
+
assertsError(error);
|
|
3941
4059
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3942
4060
|
Can not extract variables from the script
|
|
3943
4061
|
${block(error.stack || error.message)}
|
|
@@ -4001,7 +4119,7 @@
|
|
|
4001
4119
|
if (parameterNames.has(subparameterName)) {
|
|
4002
4120
|
parameterNames.delete(subparameterName);
|
|
4003
4121
|
parameterNames.add(foreach.parameterName);
|
|
4004
|
-
// <- TODO: [
|
|
4122
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
4005
4123
|
}
|
|
4006
4124
|
}
|
|
4007
4125
|
}
|
|
@@ -4802,9 +4920,7 @@
|
|
|
4802
4920
|
break scripts;
|
|
4803
4921
|
}
|
|
4804
4922
|
catch (error) {
|
|
4805
|
-
|
|
4806
|
-
throw error;
|
|
4807
|
-
}
|
|
4923
|
+
assertsError(error);
|
|
4808
4924
|
if (error instanceof UnexpectedError) {
|
|
4809
4925
|
throw error;
|
|
4810
4926
|
}
|
|
@@ -4874,9 +4990,7 @@
|
|
|
4874
4990
|
break scripts;
|
|
4875
4991
|
}
|
|
4876
4992
|
catch (error) {
|
|
4877
|
-
|
|
4878
|
-
throw error;
|
|
4879
|
-
}
|
|
4993
|
+
assertsError(error);
|
|
4880
4994
|
if (error instanceof UnexpectedError) {
|
|
4881
4995
|
throw error;
|
|
4882
4996
|
}
|
|
@@ -5497,9 +5611,7 @@
|
|
|
5497
5611
|
await Promise.all(resolving);
|
|
5498
5612
|
}
|
|
5499
5613
|
catch (error /* <- Note: [3] */) {
|
|
5500
|
-
|
|
5501
|
-
throw error;
|
|
5502
|
-
}
|
|
5614
|
+
assertsError(error);
|
|
5503
5615
|
// Note: No need to rethrow UnexpectedError
|
|
5504
5616
|
// if (error instanceof UnexpectedError) {
|
|
5505
5617
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5597,6 +5709,7 @@
|
|
|
5597
5709
|
|
|
5598
5710
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5599
5711
|
`));
|
|
5712
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5600
5713
|
}
|
|
5601
5714
|
let runCount = 0;
|
|
5602
5715
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|