@promptbook/openai 0.92.0-8 → 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 (207) hide show
  1. package/README.md +1 -5
  2. package/esm/index.es.js +84 -46
  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 +5 -1
  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 +5 -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/OpenAiExecutionTools.d.ts +4 -0
  98. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  99. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
  100. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
  101. package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
  102. package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
  103. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
  104. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
  105. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
  106. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
  107. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
  108. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +10 -7
  109. package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +1 -1
  110. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
  111. package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
  112. package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
  113. package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +1 -1
  114. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +2 -2
  115. package/esm/typings/src/prepare/prepareTasks.d.ts +8 -5
  116. package/esm/typings/src/remote-server/openapi.d.ts +1 -1
  117. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +1 -1
  118. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
  119. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +7 -6
  120. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
  121. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  122. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  123. package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
  124. package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
  125. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
  126. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
  127. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
  128. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
  129. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
  130. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  131. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
  132. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
  133. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
  134. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
  135. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
  136. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  137. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
  138. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
  139. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
  140. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
  141. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
  142. package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
  143. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
  144. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  145. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
  146. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
  147. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
  148. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
  149. package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +11 -0
  150. package/esm/typings/src/storage/local-storage/utils/IndexedDbStorageOptions.d.ts +14 -0
  151. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +8 -0
  152. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
  153. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
  154. package/esm/typings/src/types/ModelRequirements.d.ts +2 -2
  155. package/esm/typings/src/types/ModelVariant.d.ts +5 -5
  156. package/esm/typings/src/types/typeAliases.d.ts +22 -19
  157. package/esm/typings/src/utils/$Register.d.ts +8 -7
  158. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
  159. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
  160. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
  161. package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +1 -1
  162. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  163. package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
  164. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  165. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
  166. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  167. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
  168. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
  169. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
  170. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
  171. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
  172. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
  173. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
  174. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
  175. package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
  176. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  177. package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
  178. package/esm/typings/src/utils/organization/just.d.ts +1 -1
  179. package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
  180. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  181. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  182. package/esm/typings/src/utils/removeQuotes.d.ts +2 -2
  183. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  184. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  185. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -1
  186. package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +1 -1
  187. package/esm/typings/src/utils/unwrapResult.d.ts +2 -2
  188. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  189. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  190. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +1 -1
  191. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +1 -1
  192. package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +1 -1
  193. package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -1
  194. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +1 -1
  195. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -1
  196. package/esm/typings/src/version.d.ts +2 -1
  197. package/esm/typings/src/wizzard/wizzard.d.ts +1 -1
  198. package/package.json +15 -2
  199. package/umd/index.umd.js +88 -50
  200. package/umd/index.umd.js.map +1 -1
  201. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
  202. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
  203. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +0 -19
  204. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
  205. /package/esm/typings/src/llm-providers/{multiple → _multiple}/MultipleLlmExecutionTools.d.ts +0 -0
  206. /package/esm/typings/src/llm-providers/{multiple → _multiple}/joinLlmExecutionTools.d.ts +0 -0
  207. /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/openai`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -490,7 +486,7 @@ Or you can install them separately:
490
486
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
491
487
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
492
488
  - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
493
- - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
489
+ - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Useful templates and examples of books which can be used as a starting point
494
490
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
495
491
  - ⭐ **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
496
492
  - 🐋 **[Docker image](https://hub.docker.com/r/hejny/promptbook/)** - Promptbook server
package/esm/index.es.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import colors from 'colors';
2
2
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
3
  import { randomBytes } from 'crypto';
4
+ import Bottleneck from 'bottleneck';
4
5
  import OpenAI from 'openai';
5
6
 
6
7
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -17,7 +18,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
17
18
  * @generated
18
19
  * @see https://github.com/webgptorg/promptbook
19
20
  */
20
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-8';
21
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0';
21
22
  /**
22
23
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
23
24
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -112,7 +113,7 @@ class PipelineExecutionError extends Error {
112
113
  super(message);
113
114
  this.name = 'PipelineExecutionError';
114
115
  // TODO: [🐙] DRY - Maybe $randomId
115
- this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
116
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
116
117
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
117
118
  }
118
119
  }
@@ -277,7 +278,7 @@ const VALUE_STRINGS = {
277
278
  const SMALL_NUMBER = 0.001;
278
279
  // <- TODO: [🧜‍♂️]
279
280
  /**
280
- * @@@
281
+ * Default settings for parsing and generating CSV files in Promptbook.
281
282
  *
282
283
  * @public exported from `@promptbook/core`
283
284
  */
@@ -287,6 +288,14 @@ Object.freeze({
287
288
  newline: '\n',
288
289
  skipEmptyLines: true,
289
290
  });
291
+ /**
292
+ * Default rate limits (requests per minute)
293
+ *
294
+ * Note: Adjust based on the provider tier you are have
295
+ *
296
+ * @public exported from `@promptbook/core`
297
+ */
298
+ const DEFAULT_MAX_REQUESTS_PER_MINUTE = 60;
290
299
  /**
291
300
  * Note: [💞] Ignore a discrepancy between file name and entity name
292
301
  * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
@@ -362,7 +371,7 @@ class UnexpectedError extends Error {
362
371
  ${block(message)}
363
372
 
364
373
  Note: This error should not happen.
365
- It's probbably a bug in the pipeline collection
374
+ It's probably a bug in the pipeline collection
366
375
 
367
376
  Please report issue:
368
377
  ${block(getErrorReportUrl(new Error(message)).href)}
@@ -562,8 +571,12 @@ function checkSerializableAsJson(options) {
562
571
  */
563
572
 
564
573
  /**
565
- * @@@
574
+ * Creates a deep clone of the given object
575
+ *
576
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
566
577
  *
578
+ * @param objectValue The object to clone.
579
+ * @returns A deep, writable clone of the input object.
567
580
  * @public exported from `@promptbook/utils`
568
581
  */
569
582
  function deepClone(objectValue) {
@@ -625,13 +638,19 @@ function exportJson(options) {
625
638
  */
626
639
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
627
640
  /**
628
- * @@@
641
+ * Nonce which is used as string which is not occurring in normal text
642
+ *
643
+ * @private within the repository
644
+ */
645
+ const SALT_NONCE = 'ptbkghhewbvruets21t54et5';
646
+ /**
647
+ * Placeholder value indicating a parameter is missing its value.
629
648
  *
630
649
  * @private within the repository
631
650
  */
632
651
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
633
652
  /**
634
- * @@@
653
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
635
654
  *
636
655
  * @private within the repository
637
656
  */
@@ -1168,10 +1187,10 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1168
1187
  */
1169
1188
 
1170
1189
  /**
1171
- * @@@
1190
+ * Removes diacritic marks (accents) from characters in a string.
1172
1191
  *
1173
- * @param input @@@
1174
- * @returns @@@
1192
+ * @param input The string containing diacritics to be normalized.
1193
+ * @returns The string with diacritics removed or normalized.
1175
1194
  * @public exported from `@promptbook/utils`
1176
1195
  */
1177
1196
  function removeDiacritics(input) {
@@ -1222,14 +1241,18 @@ function computeUsageCounts(content) {
1222
1241
  /**
1223
1242
  * Make UncertainNumber
1224
1243
  *
1225
- * @param value
1244
+ * @param value value of the uncertain number, if `NaN` or `undefined`, it will be set to 0 and `isUncertain=true`
1245
+ * @param isUncertain if `true`, the value is uncertain, otherwise depends on the value
1226
1246
  *
1227
1247
  * @private utility for initializating UncertainNumber
1228
1248
  */
1229
- function uncertainNumber(value) {
1249
+ function uncertainNumber(value, isUncertain) {
1230
1250
  if (value === null || value === undefined || Number.isNaN(value)) {
1231
1251
  return UNCERTAIN_ZERO_VALUE;
1232
1252
  }
1253
+ if (isUncertain === true) {
1254
+ return { value, isUncertain };
1255
+ }
1233
1256
  return { value };
1234
1257
  }
1235
1258
 
@@ -1246,7 +1269,7 @@ function computeUsage(value) {
1246
1269
  /**
1247
1270
  * List of available OpenAI models with pricing
1248
1271
  *
1249
- * Note: Done at 2024-05-20
1272
+ * Note: Done at 2025-05-06
1250
1273
  *
1251
1274
  * @see https://platform.openai.com/docs/models/
1252
1275
  * @see https://openai.com/api/pricing/
@@ -1507,7 +1530,7 @@ const OPENAI_MODELS = exportJson({
1507
1530
  modelName: 'text-embedding-3-large',
1508
1531
  modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
1509
1532
  pricing: {
1510
- prompt: computeUsage(`$0.13 / 1M tokens`),
1533
+ prompt: computeUsage(`$0.13 / 1M tokens`),
1511
1534
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
1512
1535
  output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
1513
1536
  },
@@ -1600,8 +1623,8 @@ const OPENAI_MODELS = exportJson({
1600
1623
  modelName: 'gpt-4o-mini',
1601
1624
  modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
1602
1625
  pricing: {
1603
- prompt: computeUsage(`$3.00 / 1M tokens`),
1604
- output: computeUsage(`$9.00 / 1M tokens`),
1626
+ prompt: computeUsage(`$0.15 / 1M tokens`),
1627
+ output: computeUsage(`$0.60 / 1M tokens`),
1605
1628
  },
1606
1629
  },
1607
1630
  /**/
@@ -1623,7 +1646,7 @@ const OPENAI_MODELS = exportJson({
1623
1646
  modelTitle: 'o1-preview-2024-09-12',
1624
1647
  modelName: 'o1-preview-2024-09-12',
1625
1648
  modelDescription: 'September 2024 version of O1 preview with specialized reasoning capabilities for complex tasks requiring precise analytical thinking.',
1626
- // <- TODO: [💩] Some better system to organize theese date suffixes and versions
1649
+ // <- TODO: [💩] Some better system to organize these date suffixes and versions
1627
1650
  pricing: {
1628
1651
  prompt: computeUsage(`$15.00 / 1M tokens`),
1629
1652
  output: computeUsage(`$60.00 / 1M tokens`),
@@ -1729,13 +1752,21 @@ resultContent, rawResponse) {
1729
1752
  }
1730
1753
  const inputTokens = rawResponse.usage.prompt_tokens;
1731
1754
  const outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completion_tokens) || 0;
1732
- const modelInfo = OPENAI_MODELS.find((model) => model.modelName === rawResponse.model);
1755
+ let isUncertain = false;
1756
+ let modelInfo = OPENAI_MODELS.find((model) => model.modelName === rawResponse.model);
1757
+ if (modelInfo === undefined) {
1758
+ // Note: Model is not in the list of known models, fallback to the family of the models and mark price as uncertain
1759
+ modelInfo = OPENAI_MODELS.find((model) => (rawResponse.model || SALT_NONCE).startsWith(model.modelName));
1760
+ if (modelInfo !== undefined) {
1761
+ isUncertain = true;
1762
+ }
1763
+ }
1733
1764
  let price;
1734
1765
  if (modelInfo === undefined || modelInfo.pricing === undefined) {
1735
1766
  price = uncertainNumber();
1736
1767
  }
1737
1768
  else {
1738
- price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
1769
+ price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output, isUncertain);
1739
1770
  }
1740
1771
  return {
1741
1772
  price,
@@ -1770,6 +1801,10 @@ class OpenAiExecutionTools {
1770
1801
  * OpenAI API client.
1771
1802
  */
1772
1803
  this.client = null;
1804
+ // TODO: Allow configuring rate limits via options
1805
+ this.limiter = new Bottleneck({
1806
+ minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
1807
+ });
1773
1808
  }
1774
1809
  get title() {
1775
1810
  return 'OpenAI';
@@ -1869,11 +1904,12 @@ class OpenAiExecutionTools {
1869
1904
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
1870
1905
  };
1871
1906
  const start = $getCurrentDate();
1872
- let complete;
1873
1907
  if (this.options.isVerbose) {
1874
1908
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1875
1909
  }
1876
- const rawResponse = await client.chat.completions.create(rawRequest).catch((error) => {
1910
+ const rawResponse = await this.limiter
1911
+ .schedule(() => client.chat.completions.create(rawRequest))
1912
+ .catch((error) => {
1877
1913
  assertsError(error);
1878
1914
  if (this.options.isVerbose) {
1879
1915
  console.info(colors.bgRed('error'), error);
@@ -1883,6 +1919,7 @@ class OpenAiExecutionTools {
1883
1919
  if (this.options.isVerbose) {
1884
1920
  console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
1885
1921
  }
1922
+ const complete = $getCurrentDate();
1886
1923
  if (!rawResponse.choices[0]) {
1887
1924
  throw new PipelineExecutionError('No choises from OpenAI');
1888
1925
  }
@@ -1891,8 +1928,6 @@ class OpenAiExecutionTools {
1891
1928
  throw new PipelineExecutionError('More than one choise from OpenAI');
1892
1929
  }
1893
1930
  const resultContent = rawResponse.choices[0].message.content;
1894
- // eslint-disable-next-line prefer-const
1895
- complete = $getCurrentDate();
1896
1931
  const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
1897
1932
  if (resultContent === null) {
1898
1933
  throw new PipelineExecutionError('No response message from OpenAI');
@@ -1946,11 +1981,12 @@ class OpenAiExecutionTools {
1946
1981
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
1947
1982
  };
1948
1983
  const start = $getCurrentDate();
1949
- let complete;
1950
1984
  if (this.options.isVerbose) {
1951
1985
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1952
1986
  }
1953
- const rawResponse = await client.completions.create(rawRequest).catch((error) => {
1987
+ const rawResponse = await this.limiter
1988
+ .schedule(() => client.completions.create(rawRequest))
1989
+ .catch((error) => {
1954
1990
  assertsError(error);
1955
1991
  if (this.options.isVerbose) {
1956
1992
  console.info(colors.bgRed('error'), error);
@@ -1960,6 +1996,7 @@ class OpenAiExecutionTools {
1960
1996
  if (this.options.isVerbose) {
1961
1997
  console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
1962
1998
  }
1999
+ const complete = $getCurrentDate();
1963
2000
  if (!rawResponse.choices[0]) {
1964
2001
  throw new PipelineExecutionError('No choises from OpenAI');
1965
2002
  }
@@ -1968,8 +2005,6 @@ class OpenAiExecutionTools {
1968
2005
  throw new PipelineExecutionError('More than one choise from OpenAI');
1969
2006
  }
1970
2007
  const resultContent = rawResponse.choices[0].text;
1971
- // eslint-disable-next-line prefer-const
1972
- complete = $getCurrentDate();
1973
2008
  const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
1974
2009
  return exportJson({
1975
2010
  name: 'promptResult',
@@ -2010,11 +2045,12 @@ class OpenAiExecutionTools {
2010
2045
  model: modelName,
2011
2046
  };
2012
2047
  const start = $getCurrentDate();
2013
- let complete;
2014
2048
  if (this.options.isVerbose) {
2015
2049
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
2016
2050
  }
2017
- const rawResponse = await client.embeddings.create(rawRequest).catch((error) => {
2051
+ const rawResponse = await this.limiter
2052
+ .schedule(() => client.embeddings.create(rawRequest))
2053
+ .catch((error) => {
2018
2054
  assertsError(error);
2019
2055
  if (this.options.isVerbose) {
2020
2056
  console.info(colors.bgRed('error'), error);
@@ -2024,12 +2060,11 @@ class OpenAiExecutionTools {
2024
2060
  if (this.options.isVerbose) {
2025
2061
  console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2026
2062
  }
2063
+ const complete = $getCurrentDate();
2027
2064
  if (rawResponse.data.length !== 1) {
2028
2065
  throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
2029
2066
  }
2030
2067
  const resultContent = rawResponse.data[0].embedding;
2031
- // eslint-disable-next-line prefer-const
2032
- complete = $getCurrentDate();
2033
2068
  const usage = computeOpenAiUsage(content || '', '',
2034
2069
  // <- Note: Embedding does not have result content
2035
2070
  rawResponse);
@@ -2057,7 +2092,8 @@ class OpenAiExecutionTools {
2057
2092
  * Get the model that should be used as default
2058
2093
  */
2059
2094
  getDefaultModel(defaultModelName) {
2060
- const model = OPENAI_MODELS.find(({ modelName }) => modelName === defaultModelName);
2095
+ // Note: Match exact or prefix for model families
2096
+ const model = OPENAI_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
2061
2097
  if (model === undefined) {
2062
2098
  throw new UnexpectedError(spaceTrim$1((block) => `
2063
2099
  Cannot find model in OpenAI models with name "${defaultModelName}" which should be used as default.
@@ -2099,7 +2135,7 @@ class OpenAiExecutionTools {
2099
2135
  /**
2100
2136
  * Execution Tools for calling OpenAI API Assistants
2101
2137
  *
2102
- * This is usefull for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
2138
+ * This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
2103
2139
  *
2104
2140
  * @public exported from `@promptbook/openai`
2105
2141
  */
@@ -2112,6 +2148,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
2112
2148
  constructor(options) {
2113
2149
  super(options);
2114
2150
  this.assistantId = options.assistantId;
2151
+ // TODO: [👱] Make limiter same as in `OpenAiExecutionTools`
2115
2152
  }
2116
2153
  get title() {
2117
2154
  return 'OpenAI Assistant';
@@ -2303,7 +2340,8 @@ const createOpenAiExecutionTools = Object.assign((options) => {
2303
2340
  */
2304
2341
 
2305
2342
  /**
2306
- * @@@
2343
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
2344
+ * regardless of the JavaScript environment in which the code is running
2307
2345
  *
2308
2346
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
2309
2347
  *
@@ -2314,10 +2352,10 @@ function $getGlobalScope() {
2314
2352
  }
2315
2353
 
2316
2354
  /**
2317
- * @@@
2355
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2318
2356
  *
2319
- * @param text @@@
2320
- * @returns @@@
2357
+ * @param text The text string to be converted to SCREAMING_CASE format.
2358
+ * @returns The normalized text in SCREAMING_CASE format.
2321
2359
  * @example 'HELLO_WORLD'
2322
2360
  * @example 'I_LOVE_PROMPTBOOK'
2323
2361
  * @public exported from `@promptbook/utils`
@@ -2369,10 +2407,10 @@ function normalizeTo_SCREAMING_CASE(text) {
2369
2407
  */
2370
2408
 
2371
2409
  /**
2372
- * @@@
2410
+ * Normalizes a text string to snake_case format.
2373
2411
  *
2374
- * @param text @@@
2375
- * @returns @@@
2412
+ * @param text The text string to be converted to snake_case format.
2413
+ * @returns The normalized text in snake_case format.
2376
2414
  * @example 'hello_world'
2377
2415
  * @example 'i_love_promptbook'
2378
2416
  * @public exported from `@promptbook/utils`
@@ -2382,11 +2420,11 @@ function normalizeTo_snake_case(text) {
2382
2420
  }
2383
2421
 
2384
2422
  /**
2385
- * Register is @@@
2423
+ * Global registry for storing and managing registered entities of a given type.
2386
2424
  *
2387
2425
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
2388
2426
  *
2389
- * @private internal utility, exported are only signleton instances of this class
2427
+ * @private internal utility, exported are only singleton instances of this class
2390
2428
  */
2391
2429
  class $Register {
2392
2430
  constructor(registerName) {
@@ -2430,10 +2468,10 @@ class $Register {
2430
2468
  }
2431
2469
 
2432
2470
  /**
2433
- * @@@
2471
+ * Register for LLM tools.
2434
2472
  *
2435
2473
  * Note: `$` is used to indicate that this interacts with the global scope
2436
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2474
+ * @singleton Only one instance of each register is created per build, but there can be more instances across different builds or environments.
2437
2475
  * @public exported from `@promptbook/core`
2438
2476
  */
2439
2477
  const $llmToolsRegister = new $Register('llm_execution_tools_constructors');
@@ -2452,9 +2490,9 @@ const $llmToolsRegister = new $Register('llm_execution_tools_constructors');
2452
2490
  */
2453
2491
  const _OpenAiRegistration = $llmToolsRegister.register(createOpenAiExecutionTools);
2454
2492
  /**
2455
- * @@@ registration2
2493
+ * Registration of the OpenAI Assistant provider
2456
2494
  *
2457
- * Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
2495
+ * Note: [🏐] Configurations registrations are done in register-constructor.ts BUT constructor register-constructor.ts
2458
2496
  *
2459
2497
  * @public exported from `@promptbook/openai`
2460
2498
  * @public exported from `@promptbook/wizzard`