@promptbook/node 0.89.0-1 → 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 +3 -1
- package/esm/index.es.js +208 -113
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +16 -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/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 +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 -2
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +73 -3
- 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 +208 -113
- package/umd/index.umd.js.map +1 -1
- 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
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* @generated
|
|
47
47
|
* @see https://github.com/webgptorg/promptbook
|
|
48
48
|
*/
|
|
49
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
49
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
|
|
50
50
|
/**
|
|
51
51
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
52
52
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -175,6 +175,7 @@
|
|
|
175
175
|
*/
|
|
176
176
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
177
177
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
178
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
178
179
|
/**
|
|
179
180
|
* Where to store the temporary downloads
|
|
180
181
|
*
|
|
@@ -191,6 +192,15 @@
|
|
|
191
192
|
* @public exported from `@promptbook/core`
|
|
192
193
|
*/
|
|
193
194
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
195
|
+
/*
|
|
196
|
+
TODO: [🌃]
|
|
197
|
+
/**
|
|
198
|
+
* Id of application for the wizzard when using remote server
|
|
199
|
+
*
|
|
200
|
+
* @public exported from `@promptbook/core`
|
|
201
|
+
* /
|
|
202
|
+
ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
|
|
203
|
+
*/
|
|
194
204
|
/**
|
|
195
205
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
196
206
|
*
|
|
@@ -232,7 +242,7 @@
|
|
|
232
242
|
true);
|
|
233
243
|
/**
|
|
234
244
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
235
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
245
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
236
246
|
*/
|
|
237
247
|
|
|
238
248
|
/**
|
|
@@ -1700,6 +1710,19 @@
|
|
|
1700
1710
|
}
|
|
1701
1711
|
}
|
|
1702
1712
|
|
|
1713
|
+
/**
|
|
1714
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1715
|
+
*
|
|
1716
|
+
* @public exported from `@promptbook/core`
|
|
1717
|
+
*/
|
|
1718
|
+
class AuthenticationError extends Error {
|
|
1719
|
+
constructor(message) {
|
|
1720
|
+
super(message);
|
|
1721
|
+
this.name = 'AuthenticationError';
|
|
1722
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1703
1726
|
/**
|
|
1704
1727
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1705
1728
|
*
|
|
@@ -1791,6 +1814,19 @@
|
|
|
1791
1814
|
}
|
|
1792
1815
|
}
|
|
1793
1816
|
|
|
1817
|
+
/**
|
|
1818
|
+
* Error thrown when a fetch request fails
|
|
1819
|
+
*
|
|
1820
|
+
* @public exported from `@promptbook/core`
|
|
1821
|
+
*/
|
|
1822
|
+
class PromptbookFetchError extends Error {
|
|
1823
|
+
constructor(message) {
|
|
1824
|
+
super(message);
|
|
1825
|
+
this.name = 'PromptbookFetchError';
|
|
1826
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1794
1830
|
/**
|
|
1795
1831
|
* Index of all custom errors
|
|
1796
1832
|
*
|
|
@@ -1828,6 +1864,8 @@
|
|
|
1828
1864
|
TypeError,
|
|
1829
1865
|
URIError,
|
|
1830
1866
|
AggregateError,
|
|
1867
|
+
AuthenticationError,
|
|
1868
|
+
PromptbookFetchError,
|
|
1831
1869
|
/*
|
|
1832
1870
|
Note: Not widely supported
|
|
1833
1871
|
> InternalError,
|
|
@@ -1889,6 +1927,7 @@
|
|
|
1889
1927
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
1890
1928
|
for (const warning of warnings) {
|
|
1891
1929
|
console.warn(warning.message);
|
|
1930
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
1892
1931
|
}
|
|
1893
1932
|
if (isSuccessful === true) {
|
|
1894
1933
|
return;
|
|
@@ -2026,6 +2065,10 @@
|
|
|
2026
2065
|
|
|
2027
2066
|
Cannot serialize error with name "${name}"
|
|
2028
2067
|
|
|
2068
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2069
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2070
|
+
|
|
2071
|
+
|
|
2029
2072
|
${block(stack || message)}
|
|
2030
2073
|
|
|
2031
2074
|
`));
|
|
@@ -2113,30 +2156,42 @@
|
|
|
2113
2156
|
}
|
|
2114
2157
|
}
|
|
2115
2158
|
|
|
2159
|
+
/**
|
|
2160
|
+
* Represents the uncertain value
|
|
2161
|
+
*
|
|
2162
|
+
* @public exported from `@promptbook/core`
|
|
2163
|
+
*/
|
|
2164
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2165
|
+
/**
|
|
2166
|
+
* Represents the uncertain value
|
|
2167
|
+
*
|
|
2168
|
+
* @public exported from `@promptbook/core`
|
|
2169
|
+
*/
|
|
2170
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2116
2171
|
/**
|
|
2117
2172
|
* Represents the usage with no resources consumed
|
|
2118
2173
|
*
|
|
2119
2174
|
* @public exported from `@promptbook/core`
|
|
2120
2175
|
*/
|
|
2121
2176
|
const ZERO_USAGE = $deepFreeze({
|
|
2122
|
-
price:
|
|
2177
|
+
price: ZERO_VALUE,
|
|
2123
2178
|
input: {
|
|
2124
|
-
tokensCount:
|
|
2125
|
-
charactersCount:
|
|
2126
|
-
wordsCount:
|
|
2127
|
-
sentencesCount:
|
|
2128
|
-
linesCount:
|
|
2129
|
-
paragraphsCount:
|
|
2130
|
-
pagesCount:
|
|
2179
|
+
tokensCount: ZERO_VALUE,
|
|
2180
|
+
charactersCount: ZERO_VALUE,
|
|
2181
|
+
wordsCount: ZERO_VALUE,
|
|
2182
|
+
sentencesCount: ZERO_VALUE,
|
|
2183
|
+
linesCount: ZERO_VALUE,
|
|
2184
|
+
paragraphsCount: ZERO_VALUE,
|
|
2185
|
+
pagesCount: ZERO_VALUE,
|
|
2131
2186
|
},
|
|
2132
2187
|
output: {
|
|
2133
|
-
tokensCount:
|
|
2134
|
-
charactersCount:
|
|
2135
|
-
wordsCount:
|
|
2136
|
-
sentencesCount:
|
|
2137
|
-
linesCount:
|
|
2138
|
-
paragraphsCount:
|
|
2139
|
-
pagesCount:
|
|
2188
|
+
tokensCount: ZERO_VALUE,
|
|
2189
|
+
charactersCount: ZERO_VALUE,
|
|
2190
|
+
wordsCount: ZERO_VALUE,
|
|
2191
|
+
sentencesCount: ZERO_VALUE,
|
|
2192
|
+
linesCount: ZERO_VALUE,
|
|
2193
|
+
paragraphsCount: ZERO_VALUE,
|
|
2194
|
+
pagesCount: ZERO_VALUE,
|
|
2140
2195
|
},
|
|
2141
2196
|
});
|
|
2142
2197
|
/**
|
|
@@ -2145,24 +2200,24 @@
|
|
|
2145
2200
|
* @public exported from `@promptbook/core`
|
|
2146
2201
|
*/
|
|
2147
2202
|
$deepFreeze({
|
|
2148
|
-
price:
|
|
2203
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2149
2204
|
input: {
|
|
2150
|
-
tokensCount:
|
|
2151
|
-
charactersCount:
|
|
2152
|
-
wordsCount:
|
|
2153
|
-
sentencesCount:
|
|
2154
|
-
linesCount:
|
|
2155
|
-
paragraphsCount:
|
|
2156
|
-
pagesCount:
|
|
2205
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2206
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2207
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2208
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2209
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2210
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2211
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2157
2212
|
},
|
|
2158
2213
|
output: {
|
|
2159
|
-
tokensCount:
|
|
2160
|
-
charactersCount:
|
|
2161
|
-
wordsCount:
|
|
2162
|
-
sentencesCount:
|
|
2163
|
-
linesCount:
|
|
2164
|
-
paragraphsCount:
|
|
2165
|
-
pagesCount:
|
|
2214
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2215
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2216
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2217
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2218
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2219
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2220
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2166
2221
|
},
|
|
2167
2222
|
});
|
|
2168
2223
|
/**
|
|
@@ -2333,7 +2388,7 @@
|
|
|
2333
2388
|
if (parameterNames.has(subparameterName)) {
|
|
2334
2389
|
parameterNames.delete(subparameterName);
|
|
2335
2390
|
parameterNames.add(foreach.parameterName);
|
|
2336
|
-
// <- TODO: [
|
|
2391
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
2337
2392
|
}
|
|
2338
2393
|
}
|
|
2339
2394
|
}
|
|
@@ -2827,6 +2882,7 @@
|
|
|
2827
2882
|
`);
|
|
2828
2883
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2829
2884
|
console.warn(warningMessage);
|
|
2885
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2830
2886
|
/*
|
|
2831
2887
|
return {
|
|
2832
2888
|
async listModels() {
|
|
@@ -4416,6 +4472,7 @@
|
|
|
4416
4472
|
|
|
4417
4473
|
@see more at https://ptbk.io/prepare-pipeline
|
|
4418
4474
|
`));
|
|
4475
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
4419
4476
|
}
|
|
4420
4477
|
let runCount = 0;
|
|
4421
4478
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|
|
@@ -5020,17 +5077,24 @@
|
|
|
5020
5077
|
/**
|
|
5021
5078
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5022
5079
|
*
|
|
5023
|
-
* @
|
|
5080
|
+
* @public exported from `@promptbook/core`
|
|
5024
5081
|
*/
|
|
5025
|
-
const
|
|
5082
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5026
5083
|
try {
|
|
5027
|
-
return await fetch(
|
|
5084
|
+
return await fetch(urlOrRequest, init);
|
|
5028
5085
|
}
|
|
5029
5086
|
catch (error) {
|
|
5030
5087
|
if (!(error instanceof Error)) {
|
|
5031
5088
|
throw error;
|
|
5032
5089
|
}
|
|
5033
|
-
|
|
5090
|
+
let url;
|
|
5091
|
+
if (typeof urlOrRequest === 'string') {
|
|
5092
|
+
url = urlOrRequest;
|
|
5093
|
+
}
|
|
5094
|
+
else if (urlOrRequest instanceof Request) {
|
|
5095
|
+
url = urlOrRequest.url;
|
|
5096
|
+
}
|
|
5097
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
5034
5098
|
Can not fetch "${url}"
|
|
5035
5099
|
|
|
5036
5100
|
Fetch error:
|
|
@@ -5051,7 +5115,7 @@
|
|
|
5051
5115
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5052
5116
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5053
5117
|
var _a;
|
|
5054
|
-
const { fetch =
|
|
5118
|
+
const { fetch = promptbookFetch } = tools;
|
|
5055
5119
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5056
5120
|
let { name } = knowledgeSource;
|
|
5057
5121
|
const { rootDirname = null,
|
|
@@ -5192,63 +5256,73 @@
|
|
|
5192
5256
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
5193
5257
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
5194
5258
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5259
|
+
try {
|
|
5260
|
+
let partialPieces = null;
|
|
5261
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
5262
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
5263
|
+
for (const scraper of scrapers) {
|
|
5264
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
5265
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
5266
|
+
) {
|
|
5267
|
+
continue;
|
|
5268
|
+
}
|
|
5269
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
5270
|
+
if (partialPiecesUnchecked !== null) {
|
|
5271
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
5272
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
5273
|
+
break;
|
|
5274
|
+
}
|
|
5275
|
+
console.warn(spaceTrim__default["default"]((block) => `
|
|
5276
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
5212
5277
|
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5278
|
+
The source:
|
|
5279
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
5280
|
+
.split('\n')
|
|
5281
|
+
.map((line) => `> ${line}`)
|
|
5282
|
+
.join('\n'))}
|
|
5218
5283
|
|
|
5219
|
-
|
|
5284
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
5220
5285
|
|
|
5221
5286
|
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5287
|
+
`));
|
|
5288
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5289
|
+
}
|
|
5290
|
+
if (partialPieces === null) {
|
|
5291
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
|
|
5292
|
+
Cannot scrape knowledge
|
|
5227
5293
|
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5294
|
+
The source:
|
|
5295
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
5296
|
+
.split('\n')
|
|
5297
|
+
.map((line) => `> ${line}`)
|
|
5298
|
+
.join('\n'))}
|
|
5233
5299
|
|
|
5234
|
-
|
|
5300
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
5235
5301
|
|
|
5236
|
-
|
|
5302
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
5237
5303
|
|
|
5238
5304
|
|
|
5239
|
-
|
|
5305
|
+
`));
|
|
5306
|
+
}
|
|
5307
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
5308
|
+
...partialPiece,
|
|
5309
|
+
sources: [
|
|
5310
|
+
{
|
|
5311
|
+
name: knowledgeSource.name,
|
|
5312
|
+
// line, column <- TODO: [☀]
|
|
5313
|
+
// <- TODO: [❎]
|
|
5314
|
+
},
|
|
5315
|
+
],
|
|
5316
|
+
}));
|
|
5317
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
5318
|
+
}
|
|
5319
|
+
catch (error) {
|
|
5320
|
+
if (!(error instanceof Error)) {
|
|
5321
|
+
throw error;
|
|
5322
|
+
}
|
|
5323
|
+
console.warn(error);
|
|
5324
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5240
5325
|
}
|
|
5241
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
5242
|
-
...partialPiece,
|
|
5243
|
-
sources: [
|
|
5244
|
-
{
|
|
5245
|
-
name: knowledgeSource.name,
|
|
5246
|
-
// line, column <- TODO: [☀]
|
|
5247
|
-
// <- TODO: [❎]
|
|
5248
|
-
},
|
|
5249
|
-
],
|
|
5250
|
-
}));
|
|
5251
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
5252
5326
|
});
|
|
5253
5327
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
5254
5328
|
return knowledgePrepared;
|
|
@@ -7073,7 +7147,8 @@
|
|
|
7073
7147
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
7074
7148
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
7075
7149
|
console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
|
|
7076
|
-
// <- TODO: [
|
|
7150
|
+
// <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
|
|
7151
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
7077
7152
|
}
|
|
7078
7153
|
else {
|
|
7079
7154
|
throw new ParseError(spaceTrim__default["default"](`
|
|
@@ -7105,6 +7180,7 @@
|
|
|
7105
7180
|
modelVariant: 'VARIANT',
|
|
7106
7181
|
maxTokens: '???',
|
|
7107
7182
|
}[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
|
|
7183
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
7108
7184
|
}
|
|
7109
7185
|
else {
|
|
7110
7186
|
throw new ParseError(spaceTrim__default["default"](`
|
|
@@ -7384,15 +7460,15 @@
|
|
|
7384
7460
|
}
|
|
7385
7461
|
console.warn(spaceTrim__default["default"](`
|
|
7386
7462
|
|
|
7387
|
-
|
|
7463
|
+
Persona "${personaName}" is defined multiple times with different description:
|
|
7388
7464
|
|
|
7389
|
-
|
|
7390
|
-
|
|
7465
|
+
First definition:
|
|
7466
|
+
${persona.description}
|
|
7391
7467
|
|
|
7392
|
-
|
|
7393
|
-
|
|
7468
|
+
Second definition:
|
|
7469
|
+
${personaDescription}
|
|
7394
7470
|
|
|
7395
|
-
|
|
7471
|
+
`));
|
|
7396
7472
|
persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
|
|
7397
7473
|
}
|
|
7398
7474
|
|
|
@@ -9028,6 +9104,7 @@
|
|
|
9028
9104
|
}
|
|
9029
9105
|
else {
|
|
9030
9106
|
console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
|
|
9107
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
9031
9108
|
resolve('Command exceeded time limit');
|
|
9032
9109
|
}
|
|
9033
9110
|
});
|
|
@@ -9053,6 +9130,7 @@
|
|
|
9053
9130
|
output.push(stderr.toString());
|
|
9054
9131
|
if (isVerbose && stderr.toString().trim()) {
|
|
9055
9132
|
console.warn(stderr.toString());
|
|
9133
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
9056
9134
|
}
|
|
9057
9135
|
});
|
|
9058
9136
|
const finishWithCode = (code) => {
|
|
@@ -9064,6 +9142,7 @@
|
|
|
9064
9142
|
else {
|
|
9065
9143
|
if (isVerbose) {
|
|
9066
9144
|
console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
|
|
9145
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
9067
9146
|
}
|
|
9068
9147
|
resolve(spaceTrim.spaceTrim(output.join('\n')));
|
|
9069
9148
|
}
|
|
@@ -9085,6 +9164,7 @@
|
|
|
9085
9164
|
else {
|
|
9086
9165
|
if (isVerbose) {
|
|
9087
9166
|
console.warn(error);
|
|
9167
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
9088
9168
|
}
|
|
9089
9169
|
resolve(spaceTrim.spaceTrim(output.join('\n')));
|
|
9090
9170
|
}
|
|
@@ -9515,21 +9595,15 @@
|
|
|
9515
9595
|
*/
|
|
9516
9596
|
|
|
9517
9597
|
/**
|
|
9518
|
-
*
|
|
9519
|
-
*
|
|
9520
|
-
* @@@ .env
|
|
9598
|
+
* Provides the path to the `.env` file
|
|
9521
9599
|
*
|
|
9522
|
-
*
|
|
9523
|
-
* - `process.env.OPENAI_API_KEY`
|
|
9524
|
-
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9525
|
-
* - ...
|
|
9600
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9526
9601
|
*
|
|
9527
|
-
* @
|
|
9528
|
-
* @public exported from `@promptbook/node`
|
|
9602
|
+
* @private within the repository - for CLI utils
|
|
9529
9603
|
*/
|
|
9530
|
-
async function $
|
|
9604
|
+
async function $provideEnvFilename() {
|
|
9531
9605
|
if (!$isRunningInNode()) {
|
|
9532
|
-
throw new EnvironmentMismatchError('Function `$
|
|
9606
|
+
throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
|
|
9533
9607
|
}
|
|
9534
9608
|
const envFilePatterns = [
|
|
9535
9609
|
'.env',
|
|
@@ -9549,8 +9623,7 @@
|
|
|
9549
9623
|
const envFilename = path.join(rootDirname, pattern);
|
|
9550
9624
|
if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
|
|
9551
9625
|
$setUsedEnvFilename(envFilename);
|
|
9552
|
-
|
|
9553
|
-
break up_to_root;
|
|
9626
|
+
return envFilename;
|
|
9554
9627
|
}
|
|
9555
9628
|
}
|
|
9556
9629
|
if (isRootPath(rootDirname)) {
|
|
@@ -9559,6 +9632,34 @@
|
|
|
9559
9632
|
// Note: If the directory does not exist, try the parent directory
|
|
9560
9633
|
rootDirname = path.join(rootDirname, '..');
|
|
9561
9634
|
}
|
|
9635
|
+
return null;
|
|
9636
|
+
}
|
|
9637
|
+
/**
|
|
9638
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9639
|
+
*/
|
|
9640
|
+
|
|
9641
|
+
/**
|
|
9642
|
+
* @@@
|
|
9643
|
+
*
|
|
9644
|
+
* @@@ .env
|
|
9645
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9646
|
+
*
|
|
9647
|
+
* It looks for environment variables:
|
|
9648
|
+
* - `process.env.OPENAI_API_KEY`
|
|
9649
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9650
|
+
* - ...
|
|
9651
|
+
*
|
|
9652
|
+
* @returns @@@
|
|
9653
|
+
* @public exported from `@promptbook/node`
|
|
9654
|
+
*/
|
|
9655
|
+
async function $provideLlmToolsConfigurationFromEnv() {
|
|
9656
|
+
if (!$isRunningInNode()) {
|
|
9657
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
9658
|
+
}
|
|
9659
|
+
const envFilepath = await $provideEnvFilename();
|
|
9660
|
+
if (envFilepath !== null) {
|
|
9661
|
+
dotenv__namespace.config({ path: envFilepath });
|
|
9662
|
+
}
|
|
9562
9663
|
const llmToolsConfiguration = $llmToolsMetadataRegister
|
|
9563
9664
|
.list()
|
|
9564
9665
|
.map((metadata) => metadata.createConfigurationFromEnv(process.env))
|
|
@@ -9566,15 +9667,8 @@
|
|
|
9566
9667
|
return llmToolsConfiguration;
|
|
9567
9668
|
}
|
|
9568
9669
|
/**
|
|
9569
|
-
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
9570
|
-
* TODO: Add Azure OpenAI
|
|
9571
|
-
* TODO: [🧠][🍛]
|
|
9572
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
9573
9670
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9574
|
-
|
|
9575
|
-
* TODO: This should be maybe not under `_common` but under `utils`
|
|
9576
|
-
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
9577
|
-
* TODO: [®] DRY Register logic */
|
|
9671
|
+
*/
|
|
9578
9672
|
|
|
9579
9673
|
/**
|
|
9580
9674
|
* @@@
|
|
@@ -9633,6 +9727,7 @@
|
|
|
9633
9727
|
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
9634
9728
|
*
|
|
9635
9729
|
* @@@ .env
|
|
9730
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9636
9731
|
*
|
|
9637
9732
|
* It looks for environment variables:
|
|
9638
9733
|
* - `process.env.OPENAI_API_KEY`
|