@promptbook/node 0.101.0-2 → 0.101.0-20

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 (76) hide show
  1. package/esm/index.es.js +55 -46
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +20 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +14 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +14 -0
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +41 -3
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +3 -0
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +4 -22
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.d.ts +1 -26
  10. package/esm/typings/src/book-2.0/agent-source/parseParameters.d.ts +13 -0
  11. package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +8 -2
  12. package/esm/typings/src/book-2.0/commitments/DELETE/DELETE.d.ts +59 -0
  13. package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +8 -2
  14. package/esm/typings/src/book-2.0/commitments/GOAL/GOAL.d.ts +45 -0
  15. package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +1 -1
  16. package/esm/typings/src/book-2.0/commitments/MEMORY/MEMORY.d.ts +46 -0
  17. package/esm/typings/src/book-2.0/commitments/MESSAGE/MESSAGE.d.ts +47 -0
  18. package/esm/typings/src/book-2.0/commitments/META/META.d.ts +62 -0
  19. package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +31 -4
  20. package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +20 -2
  21. package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +8 -2
  22. package/esm/typings/src/book-2.0/commitments/SCENARIO/SCENARIO.d.ts +46 -0
  23. package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +8 -2
  24. package/esm/typings/src/book-2.0/commitments/index.d.ts +7 -3
  25. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +3 -0
  26. package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +2 -2
  27. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/MockedChat.d.ts +63 -0
  28. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/index.d.ts +3 -0
  29. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +15 -0
  30. package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +4 -0
  31. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +26 -0
  32. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +13 -0
  33. package/esm/typings/src/book-components/Chat/hooks/index.d.ts +2 -0
  34. package/esm/typings/src/book-components/Chat/hooks/useChatAutoScroll.d.ts +41 -0
  35. package/esm/typings/src/book-components/Chat/hooks/useSendMessageToLlmChat.d.ts +44 -0
  36. package/esm/typings/src/book-components/Chat/utils/parseMessageButtons.d.ts +22 -0
  37. package/esm/typings/src/book-components/icons/PauseIcon.d.ts +8 -0
  38. package/esm/typings/src/book-components/icons/PlayIcon.d.ts +8 -0
  39. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -2
  40. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +1 -3
  41. package/esm/typings/src/formats/csv/CsvFormatError.d.ts +1 -1
  42. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  43. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  44. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -2
  45. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +8 -2
  46. package/esm/typings/src/llm-providers/_common/utils/removeUnsupportedModelRequirements.d.ts +25 -0
  47. package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +5 -13
  48. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +11 -0
  49. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +2 -1
  50. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +54 -0
  51. package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +29 -0
  52. package/esm/typings/src/llm-providers/agent/playground/playground.d.ts +8 -0
  53. package/esm/typings/src/llm-providers/agent/register-configuration.d.ts +11 -0
  54. package/esm/typings/src/llm-providers/agent/register-constructor.d.ts +13 -0
  55. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -0
  56. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -5
  57. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -6
  58. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +15 -8
  59. package/esm/typings/src/personas/preparePersona.d.ts +1 -0
  60. package/esm/typings/src/remote-server/openapi-types.d.ts +31 -31
  61. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -2
  62. package/esm/typings/src/types/ModelRequirements.d.ts +2 -4
  63. package/esm/typings/src/utils/color/utils/colorSaturation.d.ts +1 -1
  64. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +1 -1
  65. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +1 -0
  66. package/esm/typings/src/version.d.ts +1 -1
  67. package/package.json +2 -2
  68. package/umd/index.umd.js +55 -46
  69. package/umd/index.umd.js.map +1 -1
  70. package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +0 -17
  71. package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +0 -12
  72. package/esm/typings/src/llm-providers/mocked/test/joker.test.d.ts +0 -4
  73. package/esm/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +0 -5
  74. package/esm/typings/src/llm-providers/mocked/test/mocked-completion.test.d.ts +0 -4
  75. package/esm/typings/src/scripting/_test/postprocessing.test.d.ts +0 -1
  76. /package/esm/typings/src/{cli/test/ptbk.test.d.ts → llm-providers/_common/utils/removeUnsupportedModelRequirements.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.101.0-2';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-20';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3010,6 +3010,25 @@ function mapAvailableToExpectedParameters(options) {
3010
3010
  return mappedParameters;
3011
3011
  }
3012
3012
 
3013
+ /**
3014
+ * Takes an item or an array of items and returns an array of items
3015
+ *
3016
+ * 1) Any item except array and undefined returns array with that one item (also null)
3017
+ * 2) Undefined returns empty array
3018
+ * 3) Array returns itself
3019
+ *
3020
+ * @private internal utility
3021
+ */
3022
+ function arrayableToArray(input) {
3023
+ if (input === undefined) {
3024
+ return [];
3025
+ }
3026
+ if (input instanceof Array) {
3027
+ return input;
3028
+ }
3029
+ return [input];
3030
+ }
3031
+
3013
3032
  /**
3014
3033
  * Predefined profiles for LLM providers to maintain consistency across the application
3015
3034
  * These profiles represent each provider as a virtual persona in chat interfaces
@@ -3090,12 +3109,10 @@ class MultipleLlmExecutionTools {
3090
3109
  /**
3091
3110
  * Gets array of execution tools in order of priority
3092
3111
  */
3093
- constructor(...llmExecutionTools) {
3112
+ constructor(title, ...llmExecutionTools) {
3113
+ this.title = title;
3094
3114
  this.llmExecutionTools = llmExecutionTools;
3095
3115
  }
3096
- get title() {
3097
- return 'Multiple LLM Providers';
3098
- }
3099
3116
  get description() {
3100
3117
  const innerModelsTitlesAndDescriptions = this.llmExecutionTools
3101
3118
  .map(({ title, description }, index) => {
@@ -3181,7 +3198,7 @@ class MultipleLlmExecutionTools {
3181
3198
  return await llmExecutionTools.callEmbeddingModel(prompt);
3182
3199
  // <- case [🤖]:
3183
3200
  default:
3184
- throw new UnexpectedError(`Unknown model variant "${prompt.modelRequirements.modelVariant}"`);
3201
+ throw new UnexpectedError(`Unknown model variant "${prompt.modelRequirements.modelVariant}" in ${llmExecutionTools.title}`);
3185
3202
  }
3186
3203
  }
3187
3204
  catch (error) {
@@ -3202,7 +3219,7 @@ class MultipleLlmExecutionTools {
3202
3219
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3203
3220
  // 3) ...
3204
3221
  spaceTrim((block) => `
3205
- All execution tools failed:
3222
+ All execution tools of ${this.title} failed:
3206
3223
 
3207
3224
  ${block(errors
3208
3225
  .map(({ error, llmExecutionTools }, i) => `${i + 1}) **${llmExecutionTools.title}** thrown **${error.name || 'Error'}:** ${error.message}`)
@@ -3211,11 +3228,11 @@ class MultipleLlmExecutionTools {
3211
3228
  `));
3212
3229
  }
3213
3230
  else if (this.llmExecutionTools.length === 0) {
3214
- throw new PipelineExecutionError(`You have not provided any \`LlmExecutionTools\``);
3231
+ throw new PipelineExecutionError(`You have not provided any \`LlmExecutionTools\` into ${this.title}`);
3215
3232
  }
3216
3233
  else {
3217
3234
  throw new PipelineExecutionError(spaceTrim((block) => `
3218
- You have not provided any \`LlmExecutionTools\` that support model variant "${prompt.modelRequirements.modelVariant}"
3235
+ You have not provided any \`LlmExecutionTools\` that support model variant "${prompt.modelRequirements.modelVariant}" into ${this.title}
3219
3236
 
3220
3237
  Available \`LlmExecutionTools\`:
3221
3238
  ${block(this.description)}
@@ -3245,7 +3262,7 @@ class MultipleLlmExecutionTools {
3245
3262
  *
3246
3263
  * @public exported from `@promptbook/core`
3247
3264
  */
3248
- function joinLlmExecutionTools(...llmExecutionTools) {
3265
+ function joinLlmExecutionTools(title, ...llmExecutionTools) {
3249
3266
  if (llmExecutionTools.length === 0) {
3250
3267
  const warningMessage = spaceTrim(`
3251
3268
  You have not provided any \`LlmExecutionTools\`
@@ -3277,30 +3294,27 @@ function joinLlmExecutionTools(...llmExecutionTools) {
3277
3294
  };
3278
3295
  */
3279
3296
  }
3280
- return new MultipleLlmExecutionTools(...llmExecutionTools);
3297
+ return new MultipleLlmExecutionTools(title || 'Multiple LLM Providers joined by `joinLlmExecutionTools`', ...llmExecutionTools);
3281
3298
  }
3282
3299
  /**
3283
3300
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
3284
3301
  */
3285
3302
 
3286
3303
  /**
3287
- * Takes an item or an array of items and returns an array of items
3288
- *
3289
- * 1) Any item except array and undefined returns array with that one item (also null)
3290
- * 2) Undefined returns empty array
3291
- * 3) Array returns itself
3304
+ * Just returns the given `LlmExecutionTools` or joins multiple into one
3292
3305
  *
3293
- * @private internal utility
3306
+ * @public exported from `@promptbook/core`
3294
3307
  */
3295
- function arrayableToArray(input) {
3296
- if (input === undefined) {
3297
- return [];
3298
- }
3299
- if (input instanceof Array) {
3300
- return input;
3301
- }
3302
- return [input];
3308
+ function getSingleLlmExecutionTools(oneOrMoreLlmExecutionTools) {
3309
+ const _llms = arrayableToArray(oneOrMoreLlmExecutionTools);
3310
+ const llmTools = _llms.length === 1
3311
+ ? _llms[0]
3312
+ : joinLlmExecutionTools('Multiple LLM Providers joined by `getSingleLlmExecutionTools`', ..._llms);
3313
+ return llmTools;
3303
3314
  }
3315
+ /**
3316
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
3317
+ */
3304
3318
 
3305
3319
  /**
3306
3320
  * Just says that the variable is not used but should be kept
@@ -4003,9 +4017,7 @@ async function executeAttempts(options) {
4003
4017
  $scriptPipelineExecutionErrors: [],
4004
4018
  $failedResults: [], // Track all failed attempts
4005
4019
  };
4006
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
4007
- const _llms = arrayableToArray(tools.llm);
4008
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
4020
+ const llmTools = getSingleLlmExecutionTools(tools.llm);
4009
4021
  attempts: for (let attemptIndex = -jokerParameterNames.length; attemptIndex < maxAttempts; attemptIndex++) {
4010
4022
  const isJokerAttempt = attemptIndex < 0;
4011
4023
  const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attemptIndex];
@@ -4525,9 +4537,7 @@ async function getKnowledgeForTask(options) {
4525
4537
  return ''; // <- Note: Np knowledge present, return empty string
4526
4538
  }
4527
4539
  try {
4528
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
4529
- const _llms = arrayableToArray(tools.llm);
4530
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
4540
+ const llmTools = getSingleLlmExecutionTools(tools.llm);
4531
4541
  const taskEmbeddingPrompt = {
4532
4542
  title: 'Knowledge Search',
4533
4543
  modelRequirements: {
@@ -5128,13 +5138,13 @@ function createPipelineExecutor(options) {
5128
5138
  // Calculate and update tldr based on pipeline progress
5129
5139
  const cv = newOngoingResult;
5130
5140
  // Calculate progress based on parameters resolved vs total parameters
5131
- const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
5141
+ const totalParameters = pipeline.parameters.filter((p) => !p.isInput).length;
5132
5142
  let resolvedParameters = 0;
5133
5143
  let currentTaskTitle = '';
5134
5144
  // Get the resolved parameters from output parameters
5135
5145
  if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
5136
5146
  // Count how many output parameters have non-empty values
5137
- resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
5147
+ resolvedParameters = Object.values(cv.outputParameters).filter((value) => value !== undefined && value !== null && String(value).trim() !== '').length;
5138
5148
  }
5139
5149
  // Try to determine current task from execution report
5140
5150
  if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
@@ -5307,8 +5317,7 @@ async function preparePersona(personaDescription, tools, options) {
5307
5317
  pipeline: await collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book'),
5308
5318
  tools,
5309
5319
  });
5310
- const _llms = arrayableToArray(tools.llm);
5311
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5320
+ const llmTools = getSingleLlmExecutionTools(tools.llm);
5312
5321
  const availableModels = (await llmTools.listModels())
5313
5322
  .filter(({ modelVariant }) => modelVariant === 'CHAT')
5314
5323
  .map(({ modelName, modelDescription }) => ({
@@ -5352,6 +5361,7 @@ async function preparePersona(personaDescription, tools, options) {
5352
5361
  };
5353
5362
  }
5354
5363
  /**
5364
+ * TODO: [😩] DRY `preparePersona` and `selectBestModelFromAvailable`
5355
5365
  * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
5356
5366
  * TODO: [🏢] Check validity of `modelName` in pipeline
5357
5367
  * TODO: [🏢] Check validity of `systemMessage` in pipeline
@@ -6207,9 +6217,7 @@ async function preparePipeline(pipeline, tools, options) {
6207
6217
  if (tools === undefined || tools.llm === undefined) {
6208
6218
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
6209
6219
  }
6210
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
6211
- const _llms = arrayableToArray(tools.llm);
6212
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
6220
+ const llmTools = getSingleLlmExecutionTools(tools.llm);
6213
6221
  const llmToolsWithUsage = countUsage(llmTools);
6214
6222
  // <- TODO: [🌯]
6215
6223
  /*
@@ -10564,7 +10572,7 @@ const $isRunningInWebWorker = new Function(`
10564
10572
  * @public exported from `@promptbook/core`
10565
10573
  */
10566
10574
  function createLlmToolsFromConfiguration(configuration, options = {}) {
10567
- const { isVerbose = DEFAULT_IS_VERBOSE, userId } = options;
10575
+ const { title = 'LLM Tools from Configuration', isVerbose = DEFAULT_IS_VERBOSE, userId } = options;
10568
10576
  const llmTools = configuration.map((llmConfiguration) => {
10569
10577
  const registeredItem = $llmToolsRegister
10570
10578
  .list()
@@ -10596,7 +10604,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
10596
10604
  ...llmConfiguration.options,
10597
10605
  });
10598
10606
  });
10599
- return joinLlmExecutionTools(...llmTools);
10607
+ return joinLlmExecutionTools(title, ...llmTools);
10600
10608
  }
10601
10609
  /**
10602
10610
  * TODO: [🎌] Together with `createLlmToolsFromConfiguration` + 'EXECUTION_TOOLS_CLASSES' gets to `@promptbook/core` ALL model providers, make this more efficient
@@ -11196,7 +11204,7 @@ async function $provideExecutionToolsForNode(options) {
11196
11204
  throw new EnvironmentMismatchError('Function `$getExecutionToolsForNode` works only in Node.js environment');
11197
11205
  }
11198
11206
  const fs = $provideFilesystemForNode();
11199
- const llm = await $provideLlmToolsFromEnv(options);
11207
+ const llm = await $provideLlmToolsFromEnv({ title: 'LLM Tools for Node.js', ...options });
11200
11208
  const executables = await $provideExecutablesForNode();
11201
11209
  const tools = {
11202
11210
  llm,
@@ -11629,11 +11637,12 @@ class FileCacheStorage {
11629
11637
  catch (error) {
11630
11638
  // Note: If we can't write to cache, silently ignore the error
11631
11639
  // This handles read-only filesystems, permission issues, and missing parent directories
11632
- if (error instanceof Error && (error.message.includes('EROFS') ||
11633
- error.message.includes('read-only') ||
11634
- error.message.includes('EACCES') ||
11635
- error.message.includes('EPERM') ||
11636
- error.message.includes('ENOENT'))) {
11640
+ if (error instanceof Error &&
11641
+ (error.message.includes('EROFS') ||
11642
+ error.message.includes('read-only') ||
11643
+ error.message.includes('EACCES') ||
11644
+ error.message.includes('EPERM') ||
11645
+ error.message.includes('ENOENT'))) {
11637
11646
  // Silently ignore filesystem errors - caching is optional
11638
11647
  return;
11639
11648
  }