@promptbook/anthropic-claude 0.92.0-9 → 0.92.0

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 (206) hide show
  1. package/README.md +1 -5
  2. package/esm/index.es.js +97 -104
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +26 -14
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -2
  7. package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
  8. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  9. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  10. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +0 -2
  11. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  12. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  13. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
  14. package/esm/typings/src/config.d.ts +41 -11
  15. package/esm/typings/src/constants.d.ts +43 -2
  16. package/esm/typings/src/conversion/parsePipeline.d.ts +2 -2
  17. package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
  18. package/esm/typings/src/errors/CollectionError.d.ts +1 -1
  19. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +1 -1
  20. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +2 -1
  21. package/esm/typings/src/executables/apps/locatePandoc.d.ts +2 -1
  22. package/esm/typings/src/executables/locateApp.d.ts +2 -2
  23. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +2 -1
  24. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +2 -1
  25. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +2 -1
  26. package/esm/typings/src/execution/AbstractTaskResult.d.ts +1 -1
  27. package/esm/typings/src/execution/CommonToolsOptions.d.ts +3 -3
  28. package/esm/typings/src/execution/ExecutionTask.d.ts +19 -1
  29. package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +2 -1
  30. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +4 -2
  31. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  32. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
  33. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +12 -9
  34. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +13 -10
  35. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +12 -9
  36. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
  37. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +21 -15
  38. package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
  39. package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +7 -6
  40. package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +5 -1
  41. package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +1 -1
  42. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -9
  43. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +18 -5
  44. package/esm/typings/src/execution/createPipelineExecutor/knowledgePiecesToString.d.ts +9 -0
  45. package/esm/typings/src/execution/execution-report/ExecutionReportJson.d.ts +1 -1
  46. package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
  47. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +4 -4
  48. package/esm/typings/src/execution/utils/checkExpectations.d.ts +3 -3
  49. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +3 -2
  50. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +1 -1
  51. package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +8 -6
  52. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +66 -0
  53. package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
  54. package/esm/typings/src/formats/csv/CsvSettings.d.ts +2 -2
  55. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  56. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  57. package/esm/typings/src/formats/index.d.ts +2 -2
  58. package/esm/typings/src/formats/json/JsonFormatParser.d.ts +19 -0
  59. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  60. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +0 -3
  61. package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
  62. package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
  63. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  64. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  65. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +16 -7
  66. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -1
  67. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  68. package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +2 -2
  69. package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
  70. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +2 -1
  71. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +2 -2
  72. package/esm/typings/src/formfactors/index.d.ts +33 -8
  73. package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +4 -2
  74. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  75. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +3 -2
  76. package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
  77. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
  78. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
  79. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
  80. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +4 -3
  81. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +18 -5
  82. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +11 -4
  83. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +21 -42
  84. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +9 -2
  85. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +13 -4
  86. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +10 -5
  87. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +11 -3
  88. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  89. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
  90. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +6 -0
  91. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  92. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  93. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +4 -4
  94. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +1 -1
  95. package/esm/typings/src/llm-providers/google/google-models.d.ts +1 -1
  96. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
  97. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  98. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
  99. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
  100. package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
  101. package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
  102. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
  103. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
  104. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
  105. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
  106. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
  107. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +10 -7
  108. package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +1 -1
  109. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
  110. package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
  111. package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
  112. package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +1 -1
  113. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +2 -2
  114. package/esm/typings/src/prepare/prepareTasks.d.ts +8 -5
  115. package/esm/typings/src/remote-server/openapi.d.ts +1 -1
  116. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +1 -1
  117. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
  118. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +7 -6
  119. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
  120. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  121. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  122. package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
  123. package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
  124. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
  125. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
  126. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
  127. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
  128. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
  129. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  130. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
  131. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
  132. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
  133. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
  134. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
  135. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  136. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
  137. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
  138. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
  139. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
  140. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
  141. package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
  142. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
  143. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  144. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
  145. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
  146. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
  147. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
  148. package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +11 -0
  149. package/esm/typings/src/storage/local-storage/utils/IndexedDbStorageOptions.d.ts +14 -0
  150. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +8 -0
  151. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
  152. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
  153. package/esm/typings/src/types/ModelRequirements.d.ts +2 -2
  154. package/esm/typings/src/types/ModelVariant.d.ts +5 -5
  155. package/esm/typings/src/types/typeAliases.d.ts +22 -19
  156. package/esm/typings/src/utils/$Register.d.ts +8 -7
  157. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
  158. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
  159. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
  160. package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +1 -1
  161. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  162. package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
  163. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  164. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
  165. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  166. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
  167. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
  168. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
  169. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
  170. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
  171. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
  172. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
  173. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
  174. package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
  175. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  176. package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
  177. package/esm/typings/src/utils/organization/just.d.ts +1 -1
  178. package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
  179. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  180. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  181. package/esm/typings/src/utils/removeQuotes.d.ts +2 -2
  182. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  183. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  184. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -1
  185. package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +1 -1
  186. package/esm/typings/src/utils/unwrapResult.d.ts +2 -2
  187. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  188. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  189. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +1 -1
  190. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +1 -1
  191. package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +1 -1
  192. package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -1
  193. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +1 -1
  194. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -1
  195. package/esm/typings/src/version.d.ts +2 -1
  196. package/esm/typings/src/wizzard/wizzard.d.ts +1 -1
  197. package/package.json +15 -2
  198. package/umd/index.umd.js +102 -109
  199. package/umd/index.umd.js.map +1 -1
  200. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
  201. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
  202. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +0 -19
  203. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
  204. /package/esm/typings/src/llm-providers/{multiple → _multiple}/MultipleLlmExecutionTools.d.ts +0 -0
  205. /package/esm/typings/src/llm-providers/{multiple → _multiple}/joinLlmExecutionTools.d.ts +0 -0
  206. /package/esm/typings/src/llm-providers/{multiple → _multiple}/playground/playground.d.ts +0 -0
package/README.md CHANGED
@@ -23,10 +23,6 @@
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
-
30
26
  ## 📦 Package `@promptbook/anthropic-claude`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -482,7 +478,7 @@ Or you can install them separately:
482
478
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
483
479
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
484
480
  - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
485
- - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
481
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Useful templates and examples of books which can be used as a starting point
486
482
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
487
483
  - ⭐ **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
488
484
  - 🐋 **[Docker image](https://hub.docker.com/r/hejny/promptbook/)** - Promptbook server
package/esm/index.es.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
+ import Bottleneck from 'bottleneck';
3
4
  import colors from 'colors';
4
5
  import { randomBytes } from 'crypto';
5
6
  import { io } from 'socket.io-client';
@@ -18,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
18
19
  * @generated
19
20
  * @see https://github.com/webgptorg/promptbook
20
21
  */
21
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-9';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0';
22
23
  /**
23
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
24
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -129,7 +130,7 @@ const CONNECTION_TIMEOUT_MS = 7 * 1000;
129
130
  const CONNECTION_RETRIES_LIMIT = 5;
130
131
  // <- TODO: [🧜‍♂️]
131
132
  /**
132
- * @@@
133
+ * Default settings for parsing and generating CSV files in Promptbook.
133
134
  *
134
135
  * @public exported from `@promptbook/core`
135
136
  */
@@ -139,6 +140,14 @@ Object.freeze({
139
140
  newline: '\n',
140
141
  skipEmptyLines: true,
141
142
  });
143
+ /**
144
+ * Default rate limits (requests per minute)
145
+ *
146
+ * Note: Adjust based on the provider tier you are have
147
+ *
148
+ * @public exported from `@promptbook/core`
149
+ */
150
+ const DEFAULT_MAX_REQUESTS_PER_MINUTE = 60;
142
151
  /**
143
152
  * Note: [💞] Ignore a discrepancy between file name and entity name
144
153
  * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
@@ -199,7 +208,7 @@ class UnexpectedError extends Error {
199
208
  ${block(message)}
200
209
 
201
210
  Note: This error should not happen.
202
- It's probbably a bug in the pipeline collection
211
+ It's probably a bug in the pipeline collection
203
212
 
204
213
  Please report issue:
205
214
  ${block(getErrorReportUrl(new Error(message)).href)}
@@ -399,8 +408,12 @@ function checkSerializableAsJson(options) {
399
408
  */
400
409
 
401
410
  /**
402
- * @@@
411
+ * Creates a deep clone of the given object
412
+ *
413
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
403
414
  *
415
+ * @param objectValue The object to clone.
416
+ * @returns A deep, writable clone of the input object.
404
417
  * @public exported from `@promptbook/utils`
405
418
  */
406
419
  function deepClone(objectValue) {
@@ -468,7 +481,7 @@ function computeUsage(value) {
468
481
  /**
469
482
  * List of available Anthropic Claude models with pricing
470
483
  *
471
- * Note: Done at 2024-08-16
484
+ * Note: Done at 2025-05-06
472
485
  *
473
486
  * @see https://docs.anthropic.com/en/docs/models-overview
474
487
  * @public exported from `@promptbook/anthropic-claude`
@@ -482,8 +495,8 @@ const ANTHROPIC_CLAUDE_MODELS = exportJson({
482
495
  modelName: 'claude-3-5-sonnet-20240620',
483
496
  modelDescription: 'Latest Claude model with great reasoning, coding, and language understanding capabilities. 200K context window. Optimized balance of intelligence and speed.',
484
497
  pricing: {
485
- prompt: computeUsage(`$3.00 / 1M tokens`),
486
- output: computeUsage(`$15.00 / 1M tokens`),
498
+ prompt: computeUsage(`$2.50 / 1M tokens`),
499
+ output: computeUsage(`$12.50 / 1M tokens`),
487
500
  },
488
501
  },
489
502
  {
@@ -492,8 +505,8 @@ const ANTHROPIC_CLAUDE_MODELS = exportJson({
492
505
  modelName: 'claude-3-opus-20240229',
493
506
  modelDescription: 'Most capable Claude model excelling at complex reasoning, coding, and detailed instruction following. 200K context window. Best for sophisticated tasks requiring nuanced understanding.',
494
507
  pricing: {
495
- prompt: computeUsage(`$15.00 / 1M tokens`),
496
- output: computeUsage(`$75.00 / 1M tokens`),
508
+ prompt: computeUsage(`$12.00 / 1M tokens`),
509
+ output: computeUsage(`$60.00 / 1M tokens`),
497
510
  },
498
511
  },
499
512
  {
@@ -552,8 +565,8 @@ const ANTHROPIC_CLAUDE_MODELS = exportJson({
552
565
  modelName: 'claude-3-7-sonnet-20250219',
553
566
  modelDescription: 'Latest generation Claude model with advanced reasoning and language understanding. Enhanced capabilities over 3.5 with improved domain knowledge. 200K context window.',
554
567
  pricing: {
555
- prompt: computeUsage(`$3.00 / 1M tokens`),
556
- output: computeUsage(`$15.00 / 1M tokens`),
568
+ prompt: computeUsage(`$2.50 / 1M tokens`),
569
+ output: computeUsage(`$12.50 / 1M tokens`),
557
570
  },
558
571
  },
559
572
  {
@@ -604,7 +617,7 @@ class PipelineExecutionError extends Error {
604
617
  super(message);
605
618
  this.name = 'PipelineExecutionError';
606
619
  // TODO: [🐙] DRY - Maybe $randomId
607
- this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
620
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
608
621
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
609
622
  }
610
623
  }
@@ -631,13 +644,13 @@ function $getCurrentDate() {
631
644
  */
632
645
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
633
646
  /**
634
- * @@@
647
+ * Placeholder value indicating a parameter is missing its value.
635
648
  *
636
649
  * @private within the repository
637
650
  */
638
651
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
639
652
  /**
640
- * @@@
653
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
641
654
  *
642
655
  * @private within the repository
643
656
  */
@@ -1174,10 +1187,10 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1174
1187
  */
1175
1188
 
1176
1189
  /**
1177
- * @@@
1190
+ * Removes diacritic marks (accents) from characters in a string.
1178
1191
  *
1179
- * @param input @@@
1180
- * @returns @@@
1192
+ * @param input The string containing diacritics to be normalized.
1193
+ * @returns The string with diacritics removed or normalized.
1181
1194
  * @public exported from `@promptbook/utils`
1182
1195
  */
1183
1196
  function removeDiacritics(input) {
@@ -1296,14 +1309,18 @@ $deepFreeze({
1296
1309
  /**
1297
1310
  * Make UncertainNumber
1298
1311
  *
1299
- * @param value
1312
+ * @param value value of the uncertain number, if `NaN` or `undefined`, it will be set to 0 and `isUncertain=true`
1313
+ * @param isUncertain if `true`, the value is uncertain, otherwise depends on the value
1300
1314
  *
1301
1315
  * @private utility for initializating UncertainNumber
1302
1316
  */
1303
- function uncertainNumber(value) {
1317
+ function uncertainNumber(value, isUncertain) {
1304
1318
  if (value === null || value === undefined || Number.isNaN(value)) {
1305
1319
  return UNCERTAIN_ZERO_VALUE;
1306
1320
  }
1321
+ if (isUncertain === true) {
1322
+ return { value, isUncertain };
1323
+ }
1307
1324
  return { value };
1308
1325
  }
1309
1326
 
@@ -1369,6 +1386,8 @@ class AnthropicClaudeExecutionTools {
1369
1386
  * Anthropic Claude API client.
1370
1387
  */
1371
1388
  this.client = null;
1389
+ const rate = this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE;
1390
+ this.limiter = new Bottleneck({ minTime: 60000 / rate });
1372
1391
  }
1373
1392
  get title() {
1374
1393
  return 'Anthropic Claude';
@@ -1420,8 +1439,6 @@ class AnthropicClaudeExecutionTools {
1420
1439
  // <- TODO: [🌾] Make some global max cap for maxTokens
1421
1440
  temperature: modelRequirements.temperature,
1422
1441
  system: modelRequirements.systemMessage,
1423
- // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
1424
- // <- Note: [🧆]
1425
1442
  messages: [
1426
1443
  {
1427
1444
  role: 'user',
@@ -1430,14 +1447,14 @@ class AnthropicClaudeExecutionTools {
1430
1447
  // @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
1431
1448
  },
1432
1449
  ],
1433
- // TODO: Is here some equivalent of user identification?> user: this.options.user,
1434
1450
  };
1435
1451
  const start = $getCurrentDate();
1436
- let complete;
1437
1452
  if (this.options.isVerbose) {
1438
1453
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1439
1454
  }
1440
- const rawResponse = await client.messages.create(rawRequest).catch((error) => {
1455
+ const rawResponse = await this.limiter
1456
+ .schedule(() => client.messages.create(rawRequest))
1457
+ .catch((error) => {
1441
1458
  if (this.options.isVerbose) {
1442
1459
  console.info(colors.bgRed('error'), error);
1443
1460
  }
@@ -1457,12 +1474,11 @@ class AnthropicClaudeExecutionTools {
1457
1474
  throw new PipelineExecutionError(`Returned content is not "text" type but "${contentBlock.type}"`);
1458
1475
  }
1459
1476
  const resultContent = contentBlock.text;
1460
- // eslint-disable-next-line prefer-const
1461
- complete = $getCurrentDate();
1477
+ const complete = $getCurrentDate();
1462
1478
  const usage = computeAnthropicClaudeUsage(rawPromptContent || '', resultContent || '', rawResponse);
1463
1479
  return exportJson({
1464
1480
  name: 'promptResult',
1465
- message: `Result of \`AzureOpenAiExecutionTools.callChatModel\``,
1481
+ message: `Result of \`AnthropicClaudeExecutionTools.callChatModel\``,
1466
1482
  order: [],
1467
1483
  value: {
1468
1484
  content: resultContent,
@@ -1479,83 +1495,59 @@ class AnthropicClaudeExecutionTools {
1479
1495
  },
1480
1496
  });
1481
1497
  }
1482
- /*
1483
- TODO: [👏]
1484
- public async callCompletionModel(
1485
- prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
1486
- ): Promise<CompletionPromptResult> {
1487
-
1498
+ /**
1499
+ * Calls Anthropic Claude API to use a completion model.
1500
+ */
1501
+ async callCompletionModel(prompt) {
1488
1502
  if (this.options.isVerbose) {
1489
1503
  console.info('🖋 Anthropic Claude callCompletionModel call');
1490
1504
  }
1491
-
1492
1505
  const { content, parameters, modelRequirements } = prompt;
1493
-
1494
- // TODO: [☂] Use here more modelRequirements
1495
1506
  if (modelRequirements.modelVariant !== 'COMPLETION') {
1496
1507
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
1497
1508
  }
1498
-
1509
+ const client = await this.getClient();
1499
1510
  const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
1500
- const modelSettings = {
1511
+ const rawPromptContent = templateParameters(content, { ...parameters, modelName });
1512
+ const rawRequest = {
1501
1513
  model: modelName,
1502
- max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
1503
- // <- TODO: [🌾] Make some global max cap for maxTokens
1504
- // <- TODO: Use here `systemMessage`, `temperature` and `seed`
1505
- };
1506
-
1507
- const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
1508
- ...modelSettings,
1514
+ max_tokens_to_sample: modelRequirements.maxTokens || 2000,
1515
+ temperature: modelRequirements.temperature,
1509
1516
  prompt: rawPromptContent,
1510
- user: this.options.user,
1511
1517
  };
1512
- const start: string_date_iso8601 = $getCurrentDate();
1513
- let complete: string_date_iso8601;
1514
-
1515
- if (this.options.isVerbose) {
1516
- console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1517
- }
1518
- const rawResponse = await this.client.completions.create(rawRequest).catch((error) => {
1519
- if (this.options.isVerbose) {
1520
- console.info(colors.bgRed('error'), error);
1521
- }
1522
- throw error;
1523
- });
1524
-
1525
-
1518
+ const start = $getCurrentDate();
1519
+ const rawResponse = await this.limiter
1520
+ .schedule(() => client.completions.create(rawRequest))
1521
+ .catch((error) => {
1522
+ if (this.options.isVerbose) {
1523
+ console.info(colors.bgRed('error'), error);
1524
+ }
1525
+ throw error;
1526
+ });
1526
1527
  if (this.options.isVerbose) {
1527
1528
  console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
1528
1529
  }
1529
-
1530
- if (!rawResponse.choices[0]) {
1531
- throw new PipelineExecutionError('No choises from Anthropic Claude');
1532
- }
1533
-
1534
- if (rawResponse.choices.length > 1) {
1535
- // TODO: This should be maybe only warning
1536
- throw new PipelineExecutionError('More than one choise from Anthropic Claude');
1530
+ if (!rawResponse.completion) {
1531
+ throw new PipelineExecutionError('No completion from Anthropic Claude');
1537
1532
  }
1538
-
1539
- const resultContent = rawResponse.choices[0].text;
1540
- // eslint-disable-next-line prefer-const
1541
- complete = $getCurrentDate();
1542
- const usage = { price: 'UNKNOWN', inputTokens: 0, outputTokens: 0 /* <- TODO: [🐞] Compute usage * / } satisfies Usage;
1543
-
1544
-
1545
-
1546
- return $exportJson({ name: 'promptResult',message: Result of \`AzureOpenAiExecutionTools callChatModel\`, order: [],value:{
1547
- content: resultContent,
1548
- modelName: rawResponse.model || model,
1549
- timing: {
1550
- start,
1551
- complete,
1533
+ const resultContent = rawResponse.completion;
1534
+ const complete = $getCurrentDate();
1535
+ const usage = computeAnthropicClaudeUsage(rawPromptContent, resultContent, rawResponse);
1536
+ return exportJson({
1537
+ name: 'promptResult',
1538
+ message: `Result of \`AnthropicClaudeExecutionTools.callCompletionModel\``,
1539
+ order: [],
1540
+ value: {
1541
+ content: resultContent,
1542
+ modelName: rawResponse.model || modelName,
1543
+ timing: { start, complete },
1544
+ usage,
1545
+ rawPromptContent,
1546
+ rawRequest,
1547
+ rawResponse,
1552
1548
  },
1553
- usage,
1554
- rawResponse,
1555
- // <- [🗯]
1556
1549
  });
1557
1550
  }
1558
- */
1559
1551
  // <- Note: [🤖] callXxxModel
1560
1552
  /**
1561
1553
  * Get the model that should be used as default
@@ -1564,7 +1556,7 @@ class AnthropicClaudeExecutionTools {
1564
1556
  const model = ANTHROPIC_CLAUDE_MODELS.find(({ modelName }) => modelName.startsWith(defaultModelName));
1565
1557
  if (model === undefined) {
1566
1558
  throw new UnexpectedError(spaceTrim((block) => `
1567
- Cannot find model in OpenAI models with name "${defaultModelName}" which should be used as default.
1559
+ Cannot find model in Anthropic Claude models with name "${defaultModelName}" which should be used as default.
1568
1560
 
1569
1561
  Available models:
1570
1562
  ${block(ANTHROPIC_CLAUDE_MODELS.map(({ modelName }) => `- "${modelName}"`).join('\n'))}
@@ -1634,7 +1626,7 @@ class AuthenticationError extends Error {
1634
1626
  }
1635
1627
 
1636
1628
  /**
1637
- * This error indicates that the pipeline collection cannot be propperly loaded
1629
+ * This error indicates that the pipeline collection cannot be properly loaded
1638
1630
  *
1639
1631
  * @public exported from `@promptbook/core`
1640
1632
  */
@@ -1698,7 +1690,7 @@ class MissingToolsError extends Error {
1698
1690
  super(spaceTrim$1((block) => `
1699
1691
  ${block(message)}
1700
1692
 
1701
- Note: You have probbably forgot to provide some tools for pipeline execution or preparation
1693
+ Note: You have probably forgot to provide some tools for pipeline execution or preparation
1702
1694
 
1703
1695
  `));
1704
1696
  this.name = 'MissingToolsError';
@@ -1889,7 +1881,7 @@ function deserializeError(error) {
1889
1881
  * Tests if given string is valid URL.
1890
1882
  *
1891
1883
  * Note: Dataurl are considered perfectly valid.
1892
- * Note: There are two simmilar functions:
1884
+ * Note: There are two similar functions:
1893
1885
  * - `isValidUrl` which tests any URL
1894
1886
  * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1895
1887
  *
@@ -1976,10 +1968,10 @@ class RemoteLlmExecutionTools {
1976
1968
  }
1977
1969
  get title() {
1978
1970
  // TODO: [🧠] Maybe fetch title+description from the remote server (as well as if model methods are defined)
1979
- return 'Remote server';
1971
+ return 'Promptbook remote server';
1980
1972
  }
1981
1973
  get description() {
1982
- return 'Use all models by your remote server';
1974
+ return `Models from Promptbook remote server ${this.options.remoteServerUrl}`;
1983
1975
  }
1984
1976
  /**
1985
1977
  * Check the configuration of all execution tools
@@ -1994,7 +1986,7 @@ class RemoteLlmExecutionTools {
1994
1986
  * List all available models that can be used
1995
1987
  */
1996
1988
  async listModels() {
1997
- // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
1989
+ // TODO: [👒] Listing models (and checking configuration) probably should go through REST API not Socket.io
1998
1990
  const socket = await createRemoteClient(this.options);
1999
1991
  socket.emit('listModels-request', {
2000
1992
  identification: this.options.identification,
@@ -2111,7 +2103,8 @@ const createAnthropicClaudeExecutionTools = Object.assign((options) => {
2111
2103
  */
2112
2104
 
2113
2105
  /**
2114
- * @@@
2106
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
2107
+ * regardless of the JavaScript environment in which the code is running
2115
2108
  *
2116
2109
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
2117
2110
  *
@@ -2122,10 +2115,10 @@ function $getGlobalScope() {
2122
2115
  }
2123
2116
 
2124
2117
  /**
2125
- * @@@
2118
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2126
2119
  *
2127
- * @param text @@@
2128
- * @returns @@@
2120
+ * @param text The text string to be converted to SCREAMING_CASE format.
2121
+ * @returns The normalized text in SCREAMING_CASE format.
2129
2122
  * @example 'HELLO_WORLD'
2130
2123
  * @example 'I_LOVE_PROMPTBOOK'
2131
2124
  * @public exported from `@promptbook/utils`
@@ -2177,10 +2170,10 @@ function normalizeTo_SCREAMING_CASE(text) {
2177
2170
  */
2178
2171
 
2179
2172
  /**
2180
- * @@@
2173
+ * Normalizes a text string to snake_case format.
2181
2174
  *
2182
- * @param text @@@
2183
- * @returns @@@
2175
+ * @param text The text string to be converted to snake_case format.
2176
+ * @returns The normalized text in snake_case format.
2184
2177
  * @example 'hello_world'
2185
2178
  * @example 'i_love_promptbook'
2186
2179
  * @public exported from `@promptbook/utils`
@@ -2190,11 +2183,11 @@ function normalizeTo_snake_case(text) {
2190
2183
  }
2191
2184
 
2192
2185
  /**
2193
- * Register is @@@
2186
+ * Global registry for storing and managing registered entities of a given type.
2194
2187
  *
2195
2188
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
2196
2189
  *
2197
- * @private internal utility, exported are only signleton instances of this class
2190
+ * @private internal utility, exported are only singleton instances of this class
2198
2191
  */
2199
2192
  class $Register {
2200
2193
  constructor(registerName) {
@@ -2238,10 +2231,10 @@ class $Register {
2238
2231
  }
2239
2232
 
2240
2233
  /**
2241
- * @@@
2234
+ * Register for LLM tools.
2242
2235
  *
2243
2236
  * Note: `$` is used to indicate that this interacts with the global scope
2244
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2237
+ * @singleton Only one instance of each register is created per build, but there can be more instances across different builds or environments.
2245
2238
  * @public exported from `@promptbook/core`
2246
2239
  */
2247
2240
  const $llmToolsRegister = new $Register('llm_execution_tools_constructors');