@promptbook/node 0.89.0-1 → 0.89.0-3

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.
Files changed (25) hide show
  1. package/README.md +3 -1
  2. package/esm/index.es.js +117 -86
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +6 -4
  6. package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
  7. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  8. package/esm/typings/src/execution/PromptResult.d.ts +2 -2
  9. package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
  10. package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
  11. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
  12. package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
  13. package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
  14. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
  15. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
  16. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  17. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  19. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  20. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  21. package/esm/typings/src/playground/BrjappConnector.d.ts +3 -0
  22. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  23. package/package.json +2 -2
  24. package/umd/index.umd.js +117 -86
  25. package/umd/index.umd.js.map +1 -1
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-1';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
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
@@ -1889,6 +1889,7 @@
1889
1889
  const { isSuccessful, errors, warnings } = executionResult;
1890
1890
  for (const warning of warnings) {
1891
1891
  console.warn(warning.message);
1892
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1892
1893
  }
1893
1894
  if (isSuccessful === true) {
1894
1895
  return;
@@ -2113,30 +2114,42 @@
2113
2114
  }
2114
2115
  }
2115
2116
 
2117
+ /**
2118
+ * Represents the uncertain value
2119
+ *
2120
+ * @public exported from `@promptbook/core`
2121
+ */
2122
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2123
+ /**
2124
+ * Represents the uncertain value
2125
+ *
2126
+ * @public exported from `@promptbook/core`
2127
+ */
2128
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2116
2129
  /**
2117
2130
  * Represents the usage with no resources consumed
2118
2131
  *
2119
2132
  * @public exported from `@promptbook/core`
2120
2133
  */
2121
2134
  const ZERO_USAGE = $deepFreeze({
2122
- price: { value: 0 },
2135
+ price: ZERO_VALUE,
2123
2136
  input: {
2124
- tokensCount: { value: 0 },
2125
- charactersCount: { value: 0 },
2126
- wordsCount: { value: 0 },
2127
- sentencesCount: { value: 0 },
2128
- linesCount: { value: 0 },
2129
- paragraphsCount: { value: 0 },
2130
- pagesCount: { value: 0 },
2137
+ tokensCount: ZERO_VALUE,
2138
+ charactersCount: ZERO_VALUE,
2139
+ wordsCount: ZERO_VALUE,
2140
+ sentencesCount: ZERO_VALUE,
2141
+ linesCount: ZERO_VALUE,
2142
+ paragraphsCount: ZERO_VALUE,
2143
+ pagesCount: ZERO_VALUE,
2131
2144
  },
2132
2145
  output: {
2133
- tokensCount: { value: 0 },
2134
- charactersCount: { value: 0 },
2135
- wordsCount: { value: 0 },
2136
- sentencesCount: { value: 0 },
2137
- linesCount: { value: 0 },
2138
- paragraphsCount: { value: 0 },
2139
- pagesCount: { value: 0 },
2146
+ tokensCount: ZERO_VALUE,
2147
+ charactersCount: ZERO_VALUE,
2148
+ wordsCount: ZERO_VALUE,
2149
+ sentencesCount: ZERO_VALUE,
2150
+ linesCount: ZERO_VALUE,
2151
+ paragraphsCount: ZERO_VALUE,
2152
+ pagesCount: ZERO_VALUE,
2140
2153
  },
2141
2154
  });
2142
2155
  /**
@@ -2145,24 +2158,24 @@
2145
2158
  * @public exported from `@promptbook/core`
2146
2159
  */
2147
2160
  $deepFreeze({
2148
- price: { value: 0, isUncertain: true },
2161
+ price: UNCERTAIN_ZERO_VALUE,
2149
2162
  input: {
2150
- tokensCount: { value: 0, isUncertain: true },
2151
- charactersCount: { value: 0, isUncertain: true },
2152
- wordsCount: { value: 0, isUncertain: true },
2153
- sentencesCount: { value: 0, isUncertain: true },
2154
- linesCount: { value: 0, isUncertain: true },
2155
- paragraphsCount: { value: 0, isUncertain: true },
2156
- pagesCount: { value: 0, isUncertain: true },
2163
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2164
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2165
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2166
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2167
+ linesCount: UNCERTAIN_ZERO_VALUE,
2168
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2169
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2157
2170
  },
2158
2171
  output: {
2159
- tokensCount: { value: 0, isUncertain: true },
2160
- charactersCount: { value: 0, isUncertain: true },
2161
- wordsCount: { value: 0, isUncertain: true },
2162
- sentencesCount: { value: 0, isUncertain: true },
2163
- linesCount: { value: 0, isUncertain: true },
2164
- paragraphsCount: { value: 0, isUncertain: true },
2165
- pagesCount: { value: 0, isUncertain: true },
2172
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2173
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2174
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2175
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2176
+ linesCount: UNCERTAIN_ZERO_VALUE,
2177
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2178
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2166
2179
  },
2167
2180
  });
2168
2181
  /**
@@ -2333,7 +2346,7 @@
2333
2346
  if (parameterNames.has(subparameterName)) {
2334
2347
  parameterNames.delete(subparameterName);
2335
2348
  parameterNames.add(foreach.parameterName);
2336
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
2349
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
2337
2350
  }
2338
2351
  }
2339
2352
  }
@@ -2827,6 +2840,7 @@
2827
2840
  `);
2828
2841
  // TODO: [🟥] Detect browser / node and make it colorfull
2829
2842
  console.warn(warningMessage);
2843
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2830
2844
  /*
2831
2845
  return {
2832
2846
  async listModels() {
@@ -4416,6 +4430,7 @@
4416
4430
 
4417
4431
  @see more at https://ptbk.io/prepare-pipeline
4418
4432
  `));
4433
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
4419
4434
  }
4420
4435
  let runCount = 0;
4421
4436
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -5192,63 +5207,73 @@
5192
5207
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
5193
5208
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
5194
5209
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
5195
- let partialPieces = null;
5196
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5197
- const scrapers = arrayableToArray(tools.scrapers);
5198
- for (const scraper of scrapers) {
5199
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5200
- // <- TODO: [🦔] Implement mime-type wildcards
5201
- ) {
5202
- continue;
5203
- }
5204
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5205
- if (partialPiecesUnchecked !== null) {
5206
- partialPieces = [...partialPiecesUnchecked];
5207
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5208
- break;
5209
- }
5210
- console.warn(spaceTrim__default["default"]((block) => `
5211
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5210
+ try {
5211
+ let partialPieces = null;
5212
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5213
+ const scrapers = arrayableToArray(tools.scrapers);
5214
+ for (const scraper of scrapers) {
5215
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5216
+ // <- TODO: [🦔] Implement mime-type wildcards
5217
+ ) {
5218
+ continue;
5219
+ }
5220
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5221
+ if (partialPiecesUnchecked !== null) {
5222
+ partialPieces = [...partialPiecesUnchecked];
5223
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5224
+ break;
5225
+ }
5226
+ console.warn(spaceTrim__default["default"]((block) => `
5227
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5212
5228
 
5213
- The source:
5214
- ${block(knowledgeSource.knowledgeSourceContent
5215
- .split('\n')
5216
- .map((line) => `> ${line}`)
5217
- .join('\n'))}
5229
+ The source:
5230
+ ${block(knowledgeSource.knowledgeSourceContent
5231
+ .split('\n')
5232
+ .map((line) => `> ${line}`)
5233
+ .join('\n'))}
5218
5234
 
5219
- ${block($registeredScrapersMessage(scrapers))}
5235
+ ${block($registeredScrapersMessage(scrapers))}
5220
5236
 
5221
5237
 
5222
- `));
5223
- }
5224
- if (partialPieces === null) {
5225
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5226
- Cannot scrape knowledge
5238
+ `));
5239
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5240
+ }
5241
+ if (partialPieces === null) {
5242
+ throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5243
+ Cannot scrape knowledge
5227
5244
 
5228
- The source:
5229
- > ${block(knowledgeSource.knowledgeSourceContent
5230
- .split('\n')
5231
- .map((line) => `> ${line}`)
5232
- .join('\n'))}
5245
+ The source:
5246
+ > ${block(knowledgeSource.knowledgeSourceContent
5247
+ .split('\n')
5248
+ .map((line) => `> ${line}`)
5249
+ .join('\n'))}
5233
5250
 
5234
- No scraper found for the mime type "${sourceHandler.mimeType}"
5251
+ No scraper found for the mime type "${sourceHandler.mimeType}"
5235
5252
 
5236
- ${block($registeredScrapersMessage(scrapers))}
5253
+ ${block($registeredScrapersMessage(scrapers))}
5237
5254
 
5238
5255
 
5239
- `));
5256
+ `));
5257
+ }
5258
+ const pieces = partialPieces.map((partialPiece) => ({
5259
+ ...partialPiece,
5260
+ sources: [
5261
+ {
5262
+ name: knowledgeSource.name,
5263
+ // line, column <- TODO: [☀]
5264
+ // <- TODO: [❎]
5265
+ },
5266
+ ],
5267
+ }));
5268
+ knowledgePreparedUnflatten[index] = pieces;
5269
+ }
5270
+ catch (error) {
5271
+ if (!(error instanceof Error)) {
5272
+ throw error;
5273
+ }
5274
+ console.warn(error);
5275
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5240
5276
  }
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
5277
  });
5253
5278
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
5254
5279
  return knowledgePrepared;
@@ -7073,7 +7098,8 @@
7073
7098
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
7074
7099
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
7075
7100
  console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
7076
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
7101
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
7102
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7077
7103
  }
7078
7104
  else {
7079
7105
  throw new ParseError(spaceTrim__default["default"](`
@@ -7105,6 +7131,7 @@
7105
7131
  modelVariant: 'VARIANT',
7106
7132
  maxTokens: '???',
7107
7133
  }[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
7134
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7108
7135
  }
7109
7136
  else {
7110
7137
  throw new ParseError(spaceTrim__default["default"](`
@@ -7384,15 +7411,15 @@
7384
7411
  }
7385
7412
  console.warn(spaceTrim__default["default"](`
7386
7413
 
7387
- Persona "${personaName}" is defined multiple times with different description:
7414
+ Persona "${personaName}" is defined multiple times with different description:
7388
7415
 
7389
- First definition:
7390
- ${persona.description}
7416
+ First definition:
7417
+ ${persona.description}
7391
7418
 
7392
- Second definition:
7393
- ${personaDescription}
7419
+ Second definition:
7420
+ ${personaDescription}
7394
7421
 
7395
- `));
7422
+ `));
7396
7423
  persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
7397
7424
  }
7398
7425
 
@@ -9028,6 +9055,7 @@
9028
9055
  }
9029
9056
  else {
9030
9057
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
9058
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9031
9059
  resolve('Command exceeded time limit');
9032
9060
  }
9033
9061
  });
@@ -9053,6 +9081,7 @@
9053
9081
  output.push(stderr.toString());
9054
9082
  if (isVerbose && stderr.toString().trim()) {
9055
9083
  console.warn(stderr.toString());
9084
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9056
9085
  }
9057
9086
  });
9058
9087
  const finishWithCode = (code) => {
@@ -9064,6 +9093,7 @@
9064
9093
  else {
9065
9094
  if (isVerbose) {
9066
9095
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
9096
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9067
9097
  }
9068
9098
  resolve(spaceTrim.spaceTrim(output.join('\n')));
9069
9099
  }
@@ -9085,6 +9115,7 @@
9085
9115
  else {
9086
9116
  if (isVerbose) {
9087
9117
  console.warn(error);
9118
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9088
9119
  }
9089
9120
  resolve(spaceTrim.spaceTrim(output.join('\n')));
9090
9121
  }