@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/README.md CHANGED
@@ -204,7 +204,7 @@ Each part of the book defines one of 3 circles:
204
204
 
205
205
  ### **What:** Workflows, Tasks and Parameters
206
206
 
207
- 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.
207
+ 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.
208
208
 
209
209
  **Related commands:**
210
210
 
@@ -314,6 +314,8 @@ The following glossary is used to clarify certain concepts:
314
314
 
315
315
 
316
316
 
317
+
318
+
317
319
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
318
320
 
319
321
 
package/esm/index.es.js CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1873,6 +1873,7 @@ function assertsTaskSuccessful(executionResult) {
1873
1873
  const { isSuccessful, errors, warnings } = executionResult;
1874
1874
  for (const warning of warnings) {
1875
1875
  console.warn(warning.message);
1876
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1876
1877
  }
1877
1878
  if (isSuccessful === true) {
1878
1879
  return;
@@ -2097,30 +2098,42 @@ function valueToString(value) {
2097
2098
  }
2098
2099
  }
2099
2100
 
2101
+ /**
2102
+ * Represents the uncertain value
2103
+ *
2104
+ * @public exported from `@promptbook/core`
2105
+ */
2106
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2107
+ /**
2108
+ * Represents the uncertain value
2109
+ *
2110
+ * @public exported from `@promptbook/core`
2111
+ */
2112
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2100
2113
  /**
2101
2114
  * Represents the usage with no resources consumed
2102
2115
  *
2103
2116
  * @public exported from `@promptbook/core`
2104
2117
  */
2105
2118
  const ZERO_USAGE = $deepFreeze({
2106
- price: { value: 0 },
2119
+ price: ZERO_VALUE,
2107
2120
  input: {
2108
- tokensCount: { value: 0 },
2109
- charactersCount: { value: 0 },
2110
- wordsCount: { value: 0 },
2111
- sentencesCount: { value: 0 },
2112
- linesCount: { value: 0 },
2113
- paragraphsCount: { value: 0 },
2114
- pagesCount: { value: 0 },
2121
+ tokensCount: ZERO_VALUE,
2122
+ charactersCount: ZERO_VALUE,
2123
+ wordsCount: ZERO_VALUE,
2124
+ sentencesCount: ZERO_VALUE,
2125
+ linesCount: ZERO_VALUE,
2126
+ paragraphsCount: ZERO_VALUE,
2127
+ pagesCount: ZERO_VALUE,
2115
2128
  },
2116
2129
  output: {
2117
- tokensCount: { value: 0 },
2118
- charactersCount: { value: 0 },
2119
- wordsCount: { value: 0 },
2120
- sentencesCount: { value: 0 },
2121
- linesCount: { value: 0 },
2122
- paragraphsCount: { value: 0 },
2123
- pagesCount: { value: 0 },
2130
+ tokensCount: ZERO_VALUE,
2131
+ charactersCount: ZERO_VALUE,
2132
+ wordsCount: ZERO_VALUE,
2133
+ sentencesCount: ZERO_VALUE,
2134
+ linesCount: ZERO_VALUE,
2135
+ paragraphsCount: ZERO_VALUE,
2136
+ pagesCount: ZERO_VALUE,
2124
2137
  },
2125
2138
  });
2126
2139
  /**
@@ -2129,24 +2142,24 @@ const ZERO_USAGE = $deepFreeze({
2129
2142
  * @public exported from `@promptbook/core`
2130
2143
  */
2131
2144
  $deepFreeze({
2132
- price: { value: 0, isUncertain: true },
2145
+ price: UNCERTAIN_ZERO_VALUE,
2133
2146
  input: {
2134
- tokensCount: { value: 0, isUncertain: true },
2135
- charactersCount: { value: 0, isUncertain: true },
2136
- wordsCount: { value: 0, isUncertain: true },
2137
- sentencesCount: { value: 0, isUncertain: true },
2138
- linesCount: { value: 0, isUncertain: true },
2139
- paragraphsCount: { value: 0, isUncertain: true },
2140
- pagesCount: { value: 0, isUncertain: true },
2147
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2148
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2149
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2150
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2151
+ linesCount: UNCERTAIN_ZERO_VALUE,
2152
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2153
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2141
2154
  },
2142
2155
  output: {
2143
- tokensCount: { value: 0, isUncertain: true },
2144
- charactersCount: { value: 0, isUncertain: true },
2145
- wordsCount: { value: 0, isUncertain: true },
2146
- sentencesCount: { value: 0, isUncertain: true },
2147
- linesCount: { value: 0, isUncertain: true },
2148
- paragraphsCount: { value: 0, isUncertain: true },
2149
- pagesCount: { value: 0, isUncertain: true },
2156
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2157
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2158
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2159
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2160
+ linesCount: UNCERTAIN_ZERO_VALUE,
2161
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2162
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2150
2163
  },
2151
2164
  });
2152
2165
  /**
@@ -2317,7 +2330,7 @@ function extractParameterNamesFromTask(task) {
2317
2330
  if (parameterNames.has(subparameterName)) {
2318
2331
  parameterNames.delete(subparameterName);
2319
2332
  parameterNames.add(foreach.parameterName);
2320
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
2333
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
2321
2334
  }
2322
2335
  }
2323
2336
  }
@@ -2811,6 +2824,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2811
2824
  `);
2812
2825
  // TODO: [🟥] Detect browser / node and make it colorfull
2813
2826
  console.warn(warningMessage);
2827
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2814
2828
  /*
2815
2829
  return {
2816
2830
  async listModels() {
@@ -4400,6 +4414,7 @@ function createPipelineExecutor(options) {
4400
4414
 
4401
4415
  @see more at https://ptbk.io/prepare-pipeline
4402
4416
  `));
4417
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
4403
4418
  }
4404
4419
  let runCount = 0;
4405
4420
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -5176,63 +5191,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
5176
5191
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
5177
5192
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
5178
5193
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
5179
- let partialPieces = null;
5180
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5181
- const scrapers = arrayableToArray(tools.scrapers);
5182
- for (const scraper of scrapers) {
5183
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5184
- // <- TODO: [🦔] Implement mime-type wildcards
5185
- ) {
5186
- continue;
5187
- }
5188
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5189
- if (partialPiecesUnchecked !== null) {
5190
- partialPieces = [...partialPiecesUnchecked];
5191
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5192
- break;
5193
- }
5194
- console.warn(spaceTrim((block) => `
5195
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5194
+ try {
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((block) => `
5211
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5196
5212
 
5197
- The source:
5198
- ${block(knowledgeSource.knowledgeSourceContent
5199
- .split('\n')
5200
- .map((line) => `> ${line}`)
5201
- .join('\n'))}
5213
+ The source:
5214
+ ${block(knowledgeSource.knowledgeSourceContent
5215
+ .split('\n')
5216
+ .map((line) => `> ${line}`)
5217
+ .join('\n'))}
5202
5218
 
5203
- ${block($registeredScrapersMessage(scrapers))}
5219
+ ${block($registeredScrapersMessage(scrapers))}
5204
5220
 
5205
5221
 
5206
- `));
5207
- }
5208
- if (partialPieces === null) {
5209
- throw new KnowledgeScrapeError(spaceTrim((block) => `
5210
- Cannot scrape knowledge
5222
+ `));
5223
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5224
+ }
5225
+ if (partialPieces === null) {
5226
+ throw new KnowledgeScrapeError(spaceTrim((block) => `
5227
+ Cannot scrape knowledge
5211
5228
 
5212
- The source:
5213
- > ${block(knowledgeSource.knowledgeSourceContent
5214
- .split('\n')
5215
- .map((line) => `> ${line}`)
5216
- .join('\n'))}
5229
+ The source:
5230
+ > ${block(knowledgeSource.knowledgeSourceContent
5231
+ .split('\n')
5232
+ .map((line) => `> ${line}`)
5233
+ .join('\n'))}
5217
5234
 
5218
- No scraper found for the mime type "${sourceHandler.mimeType}"
5235
+ No scraper found for the mime type "${sourceHandler.mimeType}"
5219
5236
 
5220
- ${block($registeredScrapersMessage(scrapers))}
5237
+ ${block($registeredScrapersMessage(scrapers))}
5221
5238
 
5222
5239
 
5223
- `));
5240
+ `));
5241
+ }
5242
+ const pieces = partialPieces.map((partialPiece) => ({
5243
+ ...partialPiece,
5244
+ sources: [
5245
+ {
5246
+ name: knowledgeSource.name,
5247
+ // line, column <- TODO: [☀]
5248
+ // <- TODO: [❎]
5249
+ },
5250
+ ],
5251
+ }));
5252
+ knowledgePreparedUnflatten[index] = pieces;
5253
+ }
5254
+ catch (error) {
5255
+ if (!(error instanceof Error)) {
5256
+ throw error;
5257
+ }
5258
+ console.warn(error);
5259
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5224
5260
  }
5225
- const pieces = partialPieces.map((partialPiece) => ({
5226
- ...partialPiece,
5227
- sources: [
5228
- {
5229
- name: knowledgeSource.name,
5230
- // line, column <- TODO: [☀]
5231
- // <- TODO: [❎]
5232
- },
5233
- ],
5234
- }));
5235
- knowledgePreparedUnflatten[index] = pieces;
5236
5261
  });
5237
5262
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
5238
5263
  return knowledgePrepared;
@@ -7057,7 +7082,8 @@ const modelCommandParser = {
7057
7082
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
7058
7083
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
7059
7084
  console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
7060
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
7085
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
7086
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7061
7087
  }
7062
7088
  else {
7063
7089
  throw new ParseError(spaceTrim(`
@@ -7089,6 +7115,7 @@ const modelCommandParser = {
7089
7115
  modelVariant: 'VARIANT',
7090
7116
  maxTokens: '???',
7091
7117
  }[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
7118
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7092
7119
  }
7093
7120
  else {
7094
7121
  throw new ParseError(spaceTrim(`
@@ -7368,15 +7395,15 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
7368
7395
  }
7369
7396
  console.warn(spaceTrim(`
7370
7397
 
7371
- Persona "${personaName}" is defined multiple times with different description:
7398
+ Persona "${personaName}" is defined multiple times with different description:
7372
7399
 
7373
- First definition:
7374
- ${persona.description}
7400
+ First definition:
7401
+ ${persona.description}
7375
7402
 
7376
- Second definition:
7377
- ${personaDescription}
7403
+ Second definition:
7404
+ ${personaDescription}
7378
7405
 
7379
- `));
7406
+ `));
7380
7407
  persona.description += spaceTrim('\n\n' + personaDescription);
7381
7408
  }
7382
7409
 
@@ -9012,6 +9039,7 @@ function $execCommand(options) {
9012
9039
  }
9013
9040
  else {
9014
9041
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
9042
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9015
9043
  resolve('Command exceeded time limit');
9016
9044
  }
9017
9045
  });
@@ -9037,6 +9065,7 @@ function $execCommand(options) {
9037
9065
  output.push(stderr.toString());
9038
9066
  if (isVerbose && stderr.toString().trim()) {
9039
9067
  console.warn(stderr.toString());
9068
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9040
9069
  }
9041
9070
  });
9042
9071
  const finishWithCode = (code) => {
@@ -9048,6 +9077,7 @@ function $execCommand(options) {
9048
9077
  else {
9049
9078
  if (isVerbose) {
9050
9079
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
9080
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9051
9081
  }
9052
9082
  resolve(spaceTrim$1(output.join('\n')));
9053
9083
  }
@@ -9069,6 +9099,7 @@ function $execCommand(options) {
9069
9099
  else {
9070
9100
  if (isVerbose) {
9071
9101
  console.warn(error);
9102
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9072
9103
  }
9073
9104
  resolve(spaceTrim$1(output.join('\n')));
9074
9105
  }