@promptbook/markdown-utils 0.88.0 → 0.89.0-11
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 +7 -1
- package/esm/index.es.js +162 -89
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +18 -6
- 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 -10
- 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/config.d.ts +15 -8
- package/esm/typings/src/errors/0-index.d.ts +6 -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/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- 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 +9 -2
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
- 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/playground/playground.d.ts +5 -0
- 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} +5 -4
- 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 -2
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +88 -6
- 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 +8 -2
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +1 -1
- package/umd/index.umd.js +162 -89
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/markdown-utils`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -196,7 +200,7 @@ Each part of the book defines one of 3 circles:
|
|
|
196
200
|
|
|
197
201
|
### **What:** Workflows, Tasks and Parameters
|
|
198
202
|
|
|
199
|
-
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.
|
|
203
|
+
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.
|
|
200
204
|
|
|
201
205
|
**Related commands:**
|
|
202
206
|
|
|
@@ -306,6 +310,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
306
310
|
|
|
307
311
|
|
|
308
312
|
|
|
313
|
+
|
|
314
|
+
|
|
309
315
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
310
316
|
|
|
311
317
|
|
package/esm/index.es.js
CHANGED
|
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -661,6 +661,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
661
661
|
*/
|
|
662
662
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
663
663
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
664
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
664
665
|
/**
|
|
665
666
|
* Where to store the temporary downloads
|
|
666
667
|
*
|
|
@@ -712,7 +713,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
712
713
|
true);
|
|
713
714
|
/**
|
|
714
715
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
715
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
716
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
716
717
|
*/
|
|
717
718
|
|
|
718
719
|
/**
|
|
@@ -1807,6 +1808,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
1807
1808
|
}
|
|
1808
1809
|
}
|
|
1809
1810
|
|
|
1811
|
+
/**
|
|
1812
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1813
|
+
*
|
|
1814
|
+
* @public exported from `@promptbook/core`
|
|
1815
|
+
*/
|
|
1816
|
+
class AuthenticationError extends Error {
|
|
1817
|
+
constructor(message) {
|
|
1818
|
+
super(message);
|
|
1819
|
+
this.name = 'AuthenticationError';
|
|
1820
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1810
1824
|
/**
|
|
1811
1825
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1812
1826
|
*
|
|
@@ -1898,6 +1912,19 @@ class NotYetImplementedError extends Error {
|
|
|
1898
1912
|
}
|
|
1899
1913
|
}
|
|
1900
1914
|
|
|
1915
|
+
/**
|
|
1916
|
+
* Error thrown when a fetch request fails
|
|
1917
|
+
*
|
|
1918
|
+
* @public exported from `@promptbook/core`
|
|
1919
|
+
*/
|
|
1920
|
+
class PromptbookFetchError extends Error {
|
|
1921
|
+
constructor(message) {
|
|
1922
|
+
super(message);
|
|
1923
|
+
this.name = 'PromptbookFetchError';
|
|
1924
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1901
1928
|
/**
|
|
1902
1929
|
* Index of all custom errors
|
|
1903
1930
|
*
|
|
@@ -1935,6 +1962,8 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
1935
1962
|
TypeError,
|
|
1936
1963
|
URIError,
|
|
1937
1964
|
AggregateError,
|
|
1965
|
+
AuthenticationError,
|
|
1966
|
+
PromptbookFetchError,
|
|
1938
1967
|
/*
|
|
1939
1968
|
Note: Not widely supported
|
|
1940
1969
|
> InternalError,
|
|
@@ -1996,6 +2025,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
1996
2025
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
1997
2026
|
for (const warning of warnings) {
|
|
1998
2027
|
console.warn(warning.message);
|
|
2028
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
1999
2029
|
}
|
|
2000
2030
|
if (isSuccessful === true) {
|
|
2001
2031
|
return;
|
|
@@ -2133,6 +2163,10 @@ function serializeError(error) {
|
|
|
2133
2163
|
|
|
2134
2164
|
Cannot serialize error with name "${name}"
|
|
2135
2165
|
|
|
2166
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2167
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2168
|
+
|
|
2169
|
+
|
|
2136
2170
|
${block(stack || message)}
|
|
2137
2171
|
|
|
2138
2172
|
`));
|
|
@@ -2174,30 +2208,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2174
2208
|
await Promise.all(tasks);
|
|
2175
2209
|
}
|
|
2176
2210
|
|
|
2211
|
+
/**
|
|
2212
|
+
* Represents the uncertain value
|
|
2213
|
+
*
|
|
2214
|
+
* @public exported from `@promptbook/core`
|
|
2215
|
+
*/
|
|
2216
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2217
|
+
/**
|
|
2218
|
+
* Represents the uncertain value
|
|
2219
|
+
*
|
|
2220
|
+
* @public exported from `@promptbook/core`
|
|
2221
|
+
*/
|
|
2222
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2177
2223
|
/**
|
|
2178
2224
|
* Represents the usage with no resources consumed
|
|
2179
2225
|
*
|
|
2180
2226
|
* @public exported from `@promptbook/core`
|
|
2181
2227
|
*/
|
|
2182
2228
|
const ZERO_USAGE = $deepFreeze({
|
|
2183
|
-
price:
|
|
2229
|
+
price: ZERO_VALUE,
|
|
2184
2230
|
input: {
|
|
2185
|
-
tokensCount:
|
|
2186
|
-
charactersCount:
|
|
2187
|
-
wordsCount:
|
|
2188
|
-
sentencesCount:
|
|
2189
|
-
linesCount:
|
|
2190
|
-
paragraphsCount:
|
|
2191
|
-
pagesCount:
|
|
2231
|
+
tokensCount: ZERO_VALUE,
|
|
2232
|
+
charactersCount: ZERO_VALUE,
|
|
2233
|
+
wordsCount: ZERO_VALUE,
|
|
2234
|
+
sentencesCount: ZERO_VALUE,
|
|
2235
|
+
linesCount: ZERO_VALUE,
|
|
2236
|
+
paragraphsCount: ZERO_VALUE,
|
|
2237
|
+
pagesCount: ZERO_VALUE,
|
|
2192
2238
|
},
|
|
2193
2239
|
output: {
|
|
2194
|
-
tokensCount:
|
|
2195
|
-
charactersCount:
|
|
2196
|
-
wordsCount:
|
|
2197
|
-
sentencesCount:
|
|
2198
|
-
linesCount:
|
|
2199
|
-
paragraphsCount:
|
|
2200
|
-
pagesCount:
|
|
2240
|
+
tokensCount: ZERO_VALUE,
|
|
2241
|
+
charactersCount: ZERO_VALUE,
|
|
2242
|
+
wordsCount: ZERO_VALUE,
|
|
2243
|
+
sentencesCount: ZERO_VALUE,
|
|
2244
|
+
linesCount: ZERO_VALUE,
|
|
2245
|
+
paragraphsCount: ZERO_VALUE,
|
|
2246
|
+
pagesCount: ZERO_VALUE,
|
|
2201
2247
|
},
|
|
2202
2248
|
});
|
|
2203
2249
|
/**
|
|
@@ -2206,24 +2252,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2206
2252
|
* @public exported from `@promptbook/core`
|
|
2207
2253
|
*/
|
|
2208
2254
|
$deepFreeze({
|
|
2209
|
-
price:
|
|
2255
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2210
2256
|
input: {
|
|
2211
|
-
tokensCount:
|
|
2212
|
-
charactersCount:
|
|
2213
|
-
wordsCount:
|
|
2214
|
-
sentencesCount:
|
|
2215
|
-
linesCount:
|
|
2216
|
-
paragraphsCount:
|
|
2217
|
-
pagesCount:
|
|
2257
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2258
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2259
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2260
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2261
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2262
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2263
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2218
2264
|
},
|
|
2219
2265
|
output: {
|
|
2220
|
-
tokensCount:
|
|
2221
|
-
charactersCount:
|
|
2222
|
-
wordsCount:
|
|
2223
|
-
sentencesCount:
|
|
2224
|
-
linesCount:
|
|
2225
|
-
paragraphsCount:
|
|
2226
|
-
pagesCount:
|
|
2266
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2267
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2268
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2269
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2270
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2271
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2272
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2227
2273
|
},
|
|
2228
2274
|
});
|
|
2229
2275
|
/**
|
|
@@ -2284,8 +2330,9 @@ function addUsage(...usageItems) {
|
|
|
2284
2330
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2285
2331
|
* @public exported from `@promptbook/core`
|
|
2286
2332
|
*/
|
|
2287
|
-
function
|
|
2333
|
+
function countUsage(llmTools) {
|
|
2288
2334
|
let totalUsage = ZERO_USAGE;
|
|
2335
|
+
const spending = new Subject();
|
|
2289
2336
|
const proxyTools = {
|
|
2290
2337
|
get title() {
|
|
2291
2338
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2295,12 +2342,15 @@ function countTotalUsage(llmTools) {
|
|
|
2295
2342
|
// TODO: [🧠] Maybe put here some suffix
|
|
2296
2343
|
return llmTools.description;
|
|
2297
2344
|
},
|
|
2298
|
-
|
|
2345
|
+
checkConfiguration() {
|
|
2299
2346
|
return /* not await */ llmTools.checkConfiguration();
|
|
2300
2347
|
},
|
|
2301
2348
|
listModels() {
|
|
2302
2349
|
return /* not await */ llmTools.listModels();
|
|
2303
2350
|
},
|
|
2351
|
+
spending() {
|
|
2352
|
+
return spending.asObservable();
|
|
2353
|
+
},
|
|
2304
2354
|
getTotalUsage() {
|
|
2305
2355
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2306
2356
|
return totalUsage;
|
|
@@ -2311,6 +2361,7 @@ function countTotalUsage(llmTools) {
|
|
|
2311
2361
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2312
2362
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2313
2363
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2364
|
+
spending.next(promptResult.usage);
|
|
2314
2365
|
return promptResult;
|
|
2315
2366
|
};
|
|
2316
2367
|
}
|
|
@@ -2319,6 +2370,7 @@ function countTotalUsage(llmTools) {
|
|
|
2319
2370
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2320
2371
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2321
2372
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2373
|
+
spending.next(promptResult.usage);
|
|
2322
2374
|
return promptResult;
|
|
2323
2375
|
};
|
|
2324
2376
|
}
|
|
@@ -2327,6 +2379,7 @@ function countTotalUsage(llmTools) {
|
|
|
2327
2379
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2328
2380
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2329
2381
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2382
|
+
spending.next(promptResult.usage);
|
|
2330
2383
|
return promptResult;
|
|
2331
2384
|
};
|
|
2332
2385
|
}
|
|
@@ -2504,6 +2557,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2504
2557
|
`);
|
|
2505
2558
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2506
2559
|
console.warn(warningMessage);
|
|
2560
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2507
2561
|
/*
|
|
2508
2562
|
return {
|
|
2509
2563
|
async listModels() {
|
|
@@ -3275,17 +3329,24 @@ function titleToName(value) {
|
|
|
3275
3329
|
/**
|
|
3276
3330
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3277
3331
|
*
|
|
3278
|
-
* @
|
|
3332
|
+
* @public exported from `@promptbook/core`
|
|
3279
3333
|
*/
|
|
3280
|
-
const
|
|
3334
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3281
3335
|
try {
|
|
3282
|
-
return await fetch(
|
|
3336
|
+
return await fetch(urlOrRequest, init);
|
|
3283
3337
|
}
|
|
3284
3338
|
catch (error) {
|
|
3285
3339
|
if (!(error instanceof Error)) {
|
|
3286
3340
|
throw error;
|
|
3287
3341
|
}
|
|
3288
|
-
|
|
3342
|
+
let url;
|
|
3343
|
+
if (typeof urlOrRequest === 'string') {
|
|
3344
|
+
url = urlOrRequest;
|
|
3345
|
+
}
|
|
3346
|
+
else if (urlOrRequest instanceof Request) {
|
|
3347
|
+
url = urlOrRequest.url;
|
|
3348
|
+
}
|
|
3349
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
3289
3350
|
Can not fetch "${url}"
|
|
3290
3351
|
|
|
3291
3352
|
Fetch error:
|
|
@@ -3306,7 +3367,7 @@ const scraperFetch = async (url, init) => {
|
|
|
3306
3367
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3307
3368
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3308
3369
|
var _a;
|
|
3309
|
-
const { fetch =
|
|
3370
|
+
const { fetch = promptbookFetch } = tools;
|
|
3310
3371
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3311
3372
|
let { name } = knowledgeSource;
|
|
3312
3373
|
const { rootDirname = null,
|
|
@@ -3447,63 +3508,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3447
3508
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3448
3509
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3449
3510
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3511
|
+
try {
|
|
3512
|
+
let partialPieces = null;
|
|
3513
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3514
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3515
|
+
for (const scraper of scrapers) {
|
|
3516
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3517
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3518
|
+
) {
|
|
3519
|
+
continue;
|
|
3520
|
+
}
|
|
3521
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3522
|
+
if (partialPiecesUnchecked !== null) {
|
|
3523
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3524
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3525
|
+
break;
|
|
3526
|
+
}
|
|
3527
|
+
console.warn(spaceTrim((block) => `
|
|
3528
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3467
3529
|
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3530
|
+
The source:
|
|
3531
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3532
|
+
.split('\n')
|
|
3533
|
+
.map((line) => `> ${line}`)
|
|
3534
|
+
.join('\n'))}
|
|
3473
3535
|
|
|
3474
|
-
|
|
3536
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3475
3537
|
|
|
3476
3538
|
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3539
|
+
`));
|
|
3540
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3541
|
+
}
|
|
3542
|
+
if (partialPieces === null) {
|
|
3543
|
+
throw new KnowledgeScrapeError(spaceTrim((block) => `
|
|
3544
|
+
Cannot scrape knowledge
|
|
3482
3545
|
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3546
|
+
The source:
|
|
3547
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3548
|
+
.split('\n')
|
|
3549
|
+
.map((line) => `> ${line}`)
|
|
3550
|
+
.join('\n'))}
|
|
3488
3551
|
|
|
3489
|
-
|
|
3552
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3490
3553
|
|
|
3491
|
-
|
|
3554
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3492
3555
|
|
|
3493
3556
|
|
|
3494
|
-
|
|
3557
|
+
`));
|
|
3558
|
+
}
|
|
3559
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3560
|
+
...partialPiece,
|
|
3561
|
+
sources: [
|
|
3562
|
+
{
|
|
3563
|
+
name: knowledgeSource.name,
|
|
3564
|
+
// line, column <- TODO: [☀]
|
|
3565
|
+
// <- TODO: [❎]
|
|
3566
|
+
},
|
|
3567
|
+
],
|
|
3568
|
+
}));
|
|
3569
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3570
|
+
}
|
|
3571
|
+
catch (error) {
|
|
3572
|
+
if (!(error instanceof Error)) {
|
|
3573
|
+
throw error;
|
|
3574
|
+
}
|
|
3575
|
+
console.warn(error);
|
|
3576
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3495
3577
|
}
|
|
3496
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3497
|
-
...partialPiece,
|
|
3498
|
-
sources: [
|
|
3499
|
-
{
|
|
3500
|
-
name: knowledgeSource.name,
|
|
3501
|
-
// line, column <- TODO: [☀]
|
|
3502
|
-
// <- TODO: [❎]
|
|
3503
|
-
},
|
|
3504
|
-
],
|
|
3505
|
-
}));
|
|
3506
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3507
3578
|
});
|
|
3508
3579
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3509
3580
|
return knowledgePrepared;
|
|
@@ -3609,7 +3680,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3609
3680
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3610
3681
|
const _llms = arrayableToArray(tools.llm);
|
|
3611
3682
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3612
|
-
const llmToolsWithUsage =
|
|
3683
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3613
3684
|
// <- TODO: [🌯]
|
|
3614
3685
|
/*
|
|
3615
3686
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -3921,7 +3992,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3921
3992
|
if (parameterNames.has(subparameterName)) {
|
|
3922
3993
|
parameterNames.delete(subparameterName);
|
|
3923
3994
|
parameterNames.add(foreach.parameterName);
|
|
3924
|
-
// <- TODO: [
|
|
3995
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
3925
3996
|
}
|
|
3926
3997
|
}
|
|
3927
3998
|
}
|
|
@@ -5415,6 +5486,7 @@ function createPipelineExecutor(options) {
|
|
|
5415
5486
|
|
|
5416
5487
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5417
5488
|
`));
|
|
5489
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5418
5490
|
}
|
|
5419
5491
|
let runCount = 0;
|
|
5420
5492
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|
|
@@ -5689,7 +5761,8 @@ function addAutoGeneratedSection(content, options) {
|
|
|
5689
5761
|
`));
|
|
5690
5762
|
}
|
|
5691
5763
|
console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
|
|
5692
|
-
// <- TODO: [
|
|
5764
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5765
|
+
// <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
|
|
5693
5766
|
return spaceTrim$1((block) => `
|
|
5694
5767
|
${block(content)}
|
|
5695
5768
|
|