@promptbook/node 0.88.0 → 0.89.0-2

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 (30) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +127 -89
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +16 -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 +9 -2
  16. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
  17. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  19. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  20. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  21. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  22. package/esm/typings/src/playground/BrjappConnector.d.ts +67 -0
  23. package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
  24. package/esm/typings/src/playground/playground.d.ts +5 -0
  25. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
  26. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
  27. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  28. package/package.json +2 -2
  29. package/umd/index.umd.js +127 -89
  30. 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/node`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
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.88.0';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
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) => {
@@ -4476,8 +4491,9 @@ async function forEachAsync(array, options, callbackfunction) {
4476
4491
  * @returns LLM tools with same functionality with added total cost counting
4477
4492
  * @public exported from `@promptbook/core`
4478
4493
  */
4479
- function countTotalUsage(llmTools) {
4494
+ function countUsage(llmTools) {
4480
4495
  let totalUsage = ZERO_USAGE;
4496
+ const spending = new Subject();
4481
4497
  const proxyTools = {
4482
4498
  get title() {
4483
4499
  // TODO: [🧠] Maybe put here some suffix
@@ -4487,12 +4503,15 @@ function countTotalUsage(llmTools) {
4487
4503
  // TODO: [🧠] Maybe put here some suffix
4488
4504
  return llmTools.description;
4489
4505
  },
4490
- async checkConfiguration() {
4506
+ checkConfiguration() {
4491
4507
  return /* not await */ llmTools.checkConfiguration();
4492
4508
  },
4493
4509
  listModels() {
4494
4510
  return /* not await */ llmTools.listModels();
4495
4511
  },
4512
+ spending() {
4513
+ return spending.asObservable();
4514
+ },
4496
4515
  getTotalUsage() {
4497
4516
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
4498
4517
  return totalUsage;
@@ -4503,6 +4522,7 @@ function countTotalUsage(llmTools) {
4503
4522
  // console.info('[🚕] callChatModel through countTotalUsage');
4504
4523
  const promptResult = await llmTools.callChatModel(prompt);
4505
4524
  totalUsage = addUsage(totalUsage, promptResult.usage);
4525
+ spending.next(promptResult.usage);
4506
4526
  return promptResult;
4507
4527
  };
4508
4528
  }
@@ -4511,6 +4531,7 @@ function countTotalUsage(llmTools) {
4511
4531
  // console.info('[🚕] callCompletionModel through countTotalUsage');
4512
4532
  const promptResult = await llmTools.callCompletionModel(prompt);
4513
4533
  totalUsage = addUsage(totalUsage, promptResult.usage);
4534
+ spending.next(promptResult.usage);
4514
4535
  return promptResult;
4515
4536
  };
4516
4537
  }
@@ -4519,6 +4540,7 @@ function countTotalUsage(llmTools) {
4519
4540
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
4520
4541
  const promptResult = await llmTools.callEmbeddingModel(prompt);
4521
4542
  totalUsage = addUsage(totalUsage, promptResult.usage);
4543
+ spending.next(promptResult.usage);
4522
4544
  return promptResult;
4523
4545
  };
4524
4546
  }
@@ -5169,63 +5191,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
5169
5191
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
5170
5192
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
5171
5193
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
5172
- let partialPieces = null;
5173
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5174
- const scrapers = arrayableToArray(tools.scrapers);
5175
- for (const scraper of scrapers) {
5176
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5177
- // <- TODO: [🦔] Implement mime-type wildcards
5178
- ) {
5179
- continue;
5180
- }
5181
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5182
- if (partialPiecesUnchecked !== null) {
5183
- partialPieces = [...partialPiecesUnchecked];
5184
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5185
- break;
5186
- }
5187
- console.warn(spaceTrim((block) => `
5188
- 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}".
5189
5212
 
5190
- The source:
5191
- ${block(knowledgeSource.knowledgeSourceContent
5192
- .split('\n')
5193
- .map((line) => `> ${line}`)
5194
- .join('\n'))}
5213
+ The source:
5214
+ ${block(knowledgeSource.knowledgeSourceContent
5215
+ .split('\n')
5216
+ .map((line) => `> ${line}`)
5217
+ .join('\n'))}
5195
5218
 
5196
- ${block($registeredScrapersMessage(scrapers))}
5219
+ ${block($registeredScrapersMessage(scrapers))}
5197
5220
 
5198
5221
 
5199
- `));
5200
- }
5201
- if (partialPieces === null) {
5202
- throw new KnowledgeScrapeError(spaceTrim((block) => `
5203
- 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
5204
5228
 
5205
- The source:
5206
- > ${block(knowledgeSource.knowledgeSourceContent
5207
- .split('\n')
5208
- .map((line) => `> ${line}`)
5209
- .join('\n'))}
5229
+ The source:
5230
+ > ${block(knowledgeSource.knowledgeSourceContent
5231
+ .split('\n')
5232
+ .map((line) => `> ${line}`)
5233
+ .join('\n'))}
5210
5234
 
5211
- No scraper found for the mime type "${sourceHandler.mimeType}"
5235
+ No scraper found for the mime type "${sourceHandler.mimeType}"
5212
5236
 
5213
- ${block($registeredScrapersMessage(scrapers))}
5237
+ ${block($registeredScrapersMessage(scrapers))}
5214
5238
 
5215
5239
 
5216
- `));
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
5217
5260
  }
5218
- const pieces = partialPieces.map((partialPiece) => ({
5219
- ...partialPiece,
5220
- sources: [
5221
- {
5222
- name: knowledgeSource.name,
5223
- // line, column <- TODO: [☀]
5224
- // <- TODO: [❎]
5225
- },
5226
- ],
5227
- }));
5228
- knowledgePreparedUnflatten[index] = pieces;
5229
5261
  });
5230
5262
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
5231
5263
  return knowledgePrepared;
@@ -5331,7 +5363,7 @@ async function preparePipeline(pipeline, tools, options) {
5331
5363
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5332
5364
  const _llms = arrayableToArray(tools.llm);
5333
5365
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5334
- const llmToolsWithUsage = countTotalUsage(llmTools);
5366
+ const llmToolsWithUsage = countUsage(llmTools);
5335
5367
  // <- TODO: [🌯]
5336
5368
  /*
5337
5369
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -7050,7 +7082,8 @@ const modelCommandParser = {
7050
7082
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
7051
7083
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
7052
7084
  console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
7053
- // <- 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
7054
7087
  }
7055
7088
  else {
7056
7089
  throw new ParseError(spaceTrim(`
@@ -7082,6 +7115,7 @@ const modelCommandParser = {
7082
7115
  modelVariant: 'VARIANT',
7083
7116
  maxTokens: '???',
7084
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
7085
7119
  }
7086
7120
  else {
7087
7121
  throw new ParseError(spaceTrim(`
@@ -7361,15 +7395,15 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
7361
7395
  }
7362
7396
  console.warn(spaceTrim(`
7363
7397
 
7364
- Persona "${personaName}" is defined multiple times with different description:
7398
+ Persona "${personaName}" is defined multiple times with different description:
7365
7399
 
7366
- First definition:
7367
- ${persona.description}
7400
+ First definition:
7401
+ ${persona.description}
7368
7402
 
7369
- Second definition:
7370
- ${personaDescription}
7403
+ Second definition:
7404
+ ${personaDescription}
7371
7405
 
7372
- `));
7406
+ `));
7373
7407
  persona.description += spaceTrim('\n\n' + personaDescription);
7374
7408
  }
7375
7409
 
@@ -9005,6 +9039,7 @@ function $execCommand(options) {
9005
9039
  }
9006
9040
  else {
9007
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
9008
9043
  resolve('Command exceeded time limit');
9009
9044
  }
9010
9045
  });
@@ -9030,6 +9065,7 @@ function $execCommand(options) {
9030
9065
  output.push(stderr.toString());
9031
9066
  if (isVerbose && stderr.toString().trim()) {
9032
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
9033
9069
  }
9034
9070
  });
9035
9071
  const finishWithCode = (code) => {
@@ -9041,6 +9077,7 @@ function $execCommand(options) {
9041
9077
  else {
9042
9078
  if (isVerbose) {
9043
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
9044
9081
  }
9045
9082
  resolve(spaceTrim$1(output.join('\n')));
9046
9083
  }
@@ -9062,6 +9099,7 @@ function $execCommand(options) {
9062
9099
  else {
9063
9100
  if (isVerbose) {
9064
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
9065
9103
  }
9066
9104
  resolve(spaceTrim$1(output.join('\n')));
9067
9105
  }