@promptbook/markdown-utils 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 +116 -83
  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 +1 -1
  29. package/umd/index.umd.js +116 -83
  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/markdown-utils`
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
@@ -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.88.0';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
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
@@ -1996,6 +1996,7 @@ function assertsTaskSuccessful(executionResult) {
1996
1996
  const { isSuccessful, errors, warnings } = executionResult;
1997
1997
  for (const warning of warnings) {
1998
1998
  console.warn(warning.message);
1999
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1999
2000
  }
2000
2001
  if (isSuccessful === true) {
2001
2002
  return;
@@ -2174,30 +2175,42 @@ async function forEachAsync(array, options, callbackfunction) {
2174
2175
  await Promise.all(tasks);
2175
2176
  }
2176
2177
 
2178
+ /**
2179
+ * Represents the uncertain value
2180
+ *
2181
+ * @public exported from `@promptbook/core`
2182
+ */
2183
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2184
+ /**
2185
+ * Represents the uncertain value
2186
+ *
2187
+ * @public exported from `@promptbook/core`
2188
+ */
2189
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2177
2190
  /**
2178
2191
  * Represents the usage with no resources consumed
2179
2192
  *
2180
2193
  * @public exported from `@promptbook/core`
2181
2194
  */
2182
2195
  const ZERO_USAGE = $deepFreeze({
2183
- price: { value: 0 },
2196
+ price: ZERO_VALUE,
2184
2197
  input: {
2185
- tokensCount: { value: 0 },
2186
- charactersCount: { value: 0 },
2187
- wordsCount: { value: 0 },
2188
- sentencesCount: { value: 0 },
2189
- linesCount: { value: 0 },
2190
- paragraphsCount: { value: 0 },
2191
- pagesCount: { value: 0 },
2198
+ tokensCount: ZERO_VALUE,
2199
+ charactersCount: ZERO_VALUE,
2200
+ wordsCount: ZERO_VALUE,
2201
+ sentencesCount: ZERO_VALUE,
2202
+ linesCount: ZERO_VALUE,
2203
+ paragraphsCount: ZERO_VALUE,
2204
+ pagesCount: ZERO_VALUE,
2192
2205
  },
2193
2206
  output: {
2194
- tokensCount: { value: 0 },
2195
- charactersCount: { value: 0 },
2196
- wordsCount: { value: 0 },
2197
- sentencesCount: { value: 0 },
2198
- linesCount: { value: 0 },
2199
- paragraphsCount: { value: 0 },
2200
- pagesCount: { value: 0 },
2207
+ tokensCount: ZERO_VALUE,
2208
+ charactersCount: ZERO_VALUE,
2209
+ wordsCount: ZERO_VALUE,
2210
+ sentencesCount: ZERO_VALUE,
2211
+ linesCount: ZERO_VALUE,
2212
+ paragraphsCount: ZERO_VALUE,
2213
+ pagesCount: ZERO_VALUE,
2201
2214
  },
2202
2215
  });
2203
2216
  /**
@@ -2206,24 +2219,24 @@ const ZERO_USAGE = $deepFreeze({
2206
2219
  * @public exported from `@promptbook/core`
2207
2220
  */
2208
2221
  $deepFreeze({
2209
- price: { value: 0, isUncertain: true },
2222
+ price: UNCERTAIN_ZERO_VALUE,
2210
2223
  input: {
2211
- tokensCount: { value: 0, isUncertain: true },
2212
- charactersCount: { value: 0, isUncertain: true },
2213
- wordsCount: { value: 0, isUncertain: true },
2214
- sentencesCount: { value: 0, isUncertain: true },
2215
- linesCount: { value: 0, isUncertain: true },
2216
- paragraphsCount: { value: 0, isUncertain: true },
2217
- pagesCount: { value: 0, isUncertain: true },
2224
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2225
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2226
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2227
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2228
+ linesCount: UNCERTAIN_ZERO_VALUE,
2229
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2230
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2218
2231
  },
2219
2232
  output: {
2220
- tokensCount: { value: 0, isUncertain: true },
2221
- charactersCount: { value: 0, isUncertain: true },
2222
- wordsCount: { value: 0, isUncertain: true },
2223
- sentencesCount: { value: 0, isUncertain: true },
2224
- linesCount: { value: 0, isUncertain: true },
2225
- paragraphsCount: { value: 0, isUncertain: true },
2226
- pagesCount: { value: 0, isUncertain: true },
2233
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2234
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2235
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2236
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2237
+ linesCount: UNCERTAIN_ZERO_VALUE,
2238
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2239
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2227
2240
  },
2228
2241
  });
2229
2242
  /**
@@ -2284,8 +2297,9 @@ function addUsage(...usageItems) {
2284
2297
  * @returns LLM tools with same functionality with added total cost counting
2285
2298
  * @public exported from `@promptbook/core`
2286
2299
  */
2287
- function countTotalUsage(llmTools) {
2300
+ function countUsage(llmTools) {
2288
2301
  let totalUsage = ZERO_USAGE;
2302
+ const spending = new Subject();
2289
2303
  const proxyTools = {
2290
2304
  get title() {
2291
2305
  // TODO: [🧠] Maybe put here some suffix
@@ -2295,12 +2309,15 @@ function countTotalUsage(llmTools) {
2295
2309
  // TODO: [🧠] Maybe put here some suffix
2296
2310
  return llmTools.description;
2297
2311
  },
2298
- async checkConfiguration() {
2312
+ checkConfiguration() {
2299
2313
  return /* not await */ llmTools.checkConfiguration();
2300
2314
  },
2301
2315
  listModels() {
2302
2316
  return /* not await */ llmTools.listModels();
2303
2317
  },
2318
+ spending() {
2319
+ return spending.asObservable();
2320
+ },
2304
2321
  getTotalUsage() {
2305
2322
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2306
2323
  return totalUsage;
@@ -2311,6 +2328,7 @@ function countTotalUsage(llmTools) {
2311
2328
  // console.info('[🚕] callChatModel through countTotalUsage');
2312
2329
  const promptResult = await llmTools.callChatModel(prompt);
2313
2330
  totalUsage = addUsage(totalUsage, promptResult.usage);
2331
+ spending.next(promptResult.usage);
2314
2332
  return promptResult;
2315
2333
  };
2316
2334
  }
@@ -2319,6 +2337,7 @@ function countTotalUsage(llmTools) {
2319
2337
  // console.info('[🚕] callCompletionModel through countTotalUsage');
2320
2338
  const promptResult = await llmTools.callCompletionModel(prompt);
2321
2339
  totalUsage = addUsage(totalUsage, promptResult.usage);
2340
+ spending.next(promptResult.usage);
2322
2341
  return promptResult;
2323
2342
  };
2324
2343
  }
@@ -2327,6 +2346,7 @@ function countTotalUsage(llmTools) {
2327
2346
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
2328
2347
  const promptResult = await llmTools.callEmbeddingModel(prompt);
2329
2348
  totalUsage = addUsage(totalUsage, promptResult.usage);
2349
+ spending.next(promptResult.usage);
2330
2350
  return promptResult;
2331
2351
  };
2332
2352
  }
@@ -2504,6 +2524,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2504
2524
  `);
2505
2525
  // TODO: [🟥] Detect browser / node and make it colorfull
2506
2526
  console.warn(warningMessage);
2527
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2507
2528
  /*
2508
2529
  return {
2509
2530
  async listModels() {
@@ -3447,63 +3468,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3447
3468
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3448
3469
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3449
3470
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3450
- let partialPieces = null;
3451
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3452
- const scrapers = arrayableToArray(tools.scrapers);
3453
- for (const scraper of scrapers) {
3454
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3455
- // <- TODO: [🦔] Implement mime-type wildcards
3456
- ) {
3457
- continue;
3458
- }
3459
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3460
- if (partialPiecesUnchecked !== null) {
3461
- partialPieces = [...partialPiecesUnchecked];
3462
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3463
- break;
3464
- }
3465
- console.warn(spaceTrim((block) => `
3466
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3471
+ try {
3472
+ let partialPieces = null;
3473
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3474
+ const scrapers = arrayableToArray(tools.scrapers);
3475
+ for (const scraper of scrapers) {
3476
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3477
+ // <- TODO: [🦔] Implement mime-type wildcards
3478
+ ) {
3479
+ continue;
3480
+ }
3481
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3482
+ if (partialPiecesUnchecked !== null) {
3483
+ partialPieces = [...partialPiecesUnchecked];
3484
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3485
+ break;
3486
+ }
3487
+ console.warn(spaceTrim((block) => `
3488
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3467
3489
 
3468
- The source:
3469
- ${block(knowledgeSource.knowledgeSourceContent
3470
- .split('\n')
3471
- .map((line) => `> ${line}`)
3472
- .join('\n'))}
3490
+ The source:
3491
+ ${block(knowledgeSource.knowledgeSourceContent
3492
+ .split('\n')
3493
+ .map((line) => `> ${line}`)
3494
+ .join('\n'))}
3473
3495
 
3474
- ${block($registeredScrapersMessage(scrapers))}
3496
+ ${block($registeredScrapersMessage(scrapers))}
3475
3497
 
3476
3498
 
3477
- `));
3478
- }
3479
- if (partialPieces === null) {
3480
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3481
- Cannot scrape knowledge
3499
+ `));
3500
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3501
+ }
3502
+ if (partialPieces === null) {
3503
+ throw new KnowledgeScrapeError(spaceTrim((block) => `
3504
+ Cannot scrape knowledge
3482
3505
 
3483
- The source:
3484
- > ${block(knowledgeSource.knowledgeSourceContent
3485
- .split('\n')
3486
- .map((line) => `> ${line}`)
3487
- .join('\n'))}
3506
+ The source:
3507
+ > ${block(knowledgeSource.knowledgeSourceContent
3508
+ .split('\n')
3509
+ .map((line) => `> ${line}`)
3510
+ .join('\n'))}
3488
3511
 
3489
- No scraper found for the mime type "${sourceHandler.mimeType}"
3512
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3490
3513
 
3491
- ${block($registeredScrapersMessage(scrapers))}
3514
+ ${block($registeredScrapersMessage(scrapers))}
3492
3515
 
3493
3516
 
3494
- `));
3517
+ `));
3518
+ }
3519
+ const pieces = partialPieces.map((partialPiece) => ({
3520
+ ...partialPiece,
3521
+ sources: [
3522
+ {
3523
+ name: knowledgeSource.name,
3524
+ // line, column <- TODO: [☀]
3525
+ // <- TODO: [❎]
3526
+ },
3527
+ ],
3528
+ }));
3529
+ knowledgePreparedUnflatten[index] = pieces;
3530
+ }
3531
+ catch (error) {
3532
+ if (!(error instanceof Error)) {
3533
+ throw error;
3534
+ }
3535
+ console.warn(error);
3536
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3495
3537
  }
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
3538
  });
3508
3539
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3509
3540
  return knowledgePrepared;
@@ -3609,7 +3640,7 @@ async function preparePipeline(pipeline, tools, options) {
3609
3640
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3610
3641
  const _llms = arrayableToArray(tools.llm);
3611
3642
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3612
- const llmToolsWithUsage = countTotalUsage(llmTools);
3643
+ const llmToolsWithUsage = countUsage(llmTools);
3613
3644
  // <- TODO: [🌯]
3614
3645
  /*
3615
3646
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -3921,7 +3952,7 @@ function extractParameterNamesFromTask(task) {
3921
3952
  if (parameterNames.has(subparameterName)) {
3922
3953
  parameterNames.delete(subparameterName);
3923
3954
  parameterNames.add(foreach.parameterName);
3924
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3955
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3925
3956
  }
3926
3957
  }
3927
3958
  }
@@ -5415,6 +5446,7 @@ function createPipelineExecutor(options) {
5415
5446
 
5416
5447
  @see more at https://ptbk.io/prepare-pipeline
5417
5448
  `));
5449
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5418
5450
  }
5419
5451
  let runCount = 0;
5420
5452
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -5689,7 +5721,8 @@ function addAutoGeneratedSection(content, options) {
5689
5721
  `));
5690
5722
  }
5691
5723
  console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
5692
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
5724
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5725
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
5693
5726
  return spaceTrim$1((block) => `
5694
5727
  ${block(content)}
5695
5728