@promptbook/openai 0.92.0-3 → 0.92.0-30

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 (171) hide show
  1. package/esm/index.es.js +97 -41
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +22 -6
  5. package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/google.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/types.index.d.ts +4 -2
  8. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  9. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +1 -1
  10. package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
  11. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  12. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  13. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +0 -2
  14. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  15. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  16. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
  17. package/esm/typings/src/config.d.ts +41 -11
  18. package/esm/typings/src/constants.d.ts +43 -2
  19. package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
  20. package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
  21. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +1 -1
  22. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +2 -1
  23. package/esm/typings/src/executables/apps/locatePandoc.d.ts +2 -1
  24. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +2 -1
  25. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +2 -1
  26. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +2 -1
  27. package/esm/typings/src/execution/AbstractTaskResult.d.ts +1 -1
  28. package/esm/typings/src/execution/CommonToolsOptions.d.ts +5 -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/createPipelineExecutor/$OngoingTaskResult.d.ts +12 -9
  32. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
  33. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
  34. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
  35. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +20 -14
  36. package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
  37. package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +7 -6
  38. package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +5 -1
  39. package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +1 -1
  40. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +21 -5
  41. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +19 -5
  42. package/esm/typings/src/execution/createPipelineExecutor/knowledgePiecesToString.d.ts +9 -0
  43. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +4 -4
  44. package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
  45. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +3 -2
  46. package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +8 -6
  47. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +66 -0
  48. package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
  49. package/esm/typings/src/formats/csv/CsvSettings.d.ts +2 -2
  50. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  51. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  52. package/esm/typings/src/formats/index.d.ts +2 -2
  53. package/esm/typings/src/formats/json/{JsonFormatDefinition.d.ts → JsonFormatParser.d.ts} +6 -6
  54. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  55. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +8 -0
  56. package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
  57. package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
  58. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  59. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  60. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +16 -7
  61. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -1
  62. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  63. package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +2 -2
  64. package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
  65. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +2 -1
  66. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +2 -2
  67. package/esm/typings/src/formfactors/index.d.ts +33 -8
  68. package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +4 -2
  69. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  70. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +3 -2
  71. package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
  72. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
  73. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
  74. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
  75. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +4 -3
  76. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +17 -4
  77. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +11 -4
  78. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +27 -5
  79. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +9 -2
  80. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +12 -3
  81. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +10 -5
  82. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +5 -3
  83. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  84. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
  85. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  86. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
  87. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
  88. package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
  89. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
  90. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  91. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
  92. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
  93. package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
  94. package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
  95. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  96. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
  97. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
  98. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
  99. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
  100. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
  101. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +9 -6
  102. package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
  103. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
  104. package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
  105. package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
  106. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +1 -1
  107. package/esm/typings/src/prepare/prepareTasks.d.ts +7 -4
  108. package/esm/typings/src/remote-server/openapi-types.d.ts +348 -6
  109. package/esm/typings/src/remote-server/openapi.d.ts +398 -4
  110. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +2 -1
  111. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
  112. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  113. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  114. package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
  115. package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
  116. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
  117. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
  118. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
  119. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
  120. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  121. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
  122. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
  123. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
  124. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
  125. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
  126. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  127. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
  128. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
  129. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
  130. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
  131. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
  132. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
  133. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
  134. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
  135. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
  136. package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +10 -0
  137. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +7 -0
  138. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
  139. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
  140. package/esm/typings/src/types/ModelVariant.d.ts +5 -5
  141. package/esm/typings/src/types/typeAliases.d.ts +17 -13
  142. package/esm/typings/src/utils/$Register.d.ts +8 -7
  143. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
  144. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
  145. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
  146. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  147. package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
  148. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
  149. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
  150. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
  151. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
  152. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
  153. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
  154. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
  155. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
  156. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
  157. package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
  158. package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
  159. package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
  160. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  161. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  162. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  163. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  164. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  165. package/esm/typings/src/version.d.ts +2 -1
  166. package/package.json +3 -2
  167. package/umd/index.umd.js +101 -45
  168. package/umd/index.umd.js.map +1 -1
  169. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
  170. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
  171. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
@@ -2,8 +2,8 @@
2
2
  * Organizational helper to better mark the place where to really use empty object `{}`
3
3
  *
4
4
  * Note: There are 2 similar types>
5
- * - `empty_object` @@@
6
- * - `just_empty_object` @@@
5
+ * - `empty_object` Type used for empty data objects allowing for potential future extensions
6
+ * - `just_empty_object` Type used when an object must remain permanently empty
7
7
  *
8
8
  * @private within the repository
9
9
  */
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Organizational helper to better @@@@
2
+ * Organizational helper to better distinguish different empty object use cases.
3
3
  *
4
- * Note: There are 2 similar types>
5
- * - `empty_object` @@@
6
- * - `just_empty_object` @@@
4
+ * Note: There are 2 similar types:
5
+ * - `empty_object` Type used for empty data objects with potential extensions
6
+ * - `just_empty_object` Type used specifically for objects that must remain empty
7
7
  *
8
8
  * Note: In most cases, you should use `empty_object`
9
9
  *
@@ -1,26 +1,26 @@
1
1
  import type { string_parameter_name } from '../../types/typeAliases';
2
2
  import type { string_parameter_value } from '../../types/typeAliases';
3
3
  /**
4
- * @@@
4
+ * Options for mapping available parameters to expected parameters in a pipeline task.
5
5
  */
6
6
  type MakeapAvailableToExpectedParametersOptions = {
7
7
  /**
8
- * @@@
8
+ * The set of expected parameter names (keys) for the task, all values are null.
9
9
  */
10
10
  readonly expectedParameters: Readonly<Record<string_parameter_name, null>>;
11
11
  /**
12
- * @@@
12
+ * The set of available parameters (name-value pairs) to map to the expected parameters.
13
13
  */
14
14
  readonly availableParameters: Readonly<Record<string_parameter_name, string_parameter_value>>;
15
15
  };
16
16
  /**
17
- * Maps available parameters to expected parameters
17
+ * Maps available parameters to expected parameters for a pipeline task.
18
18
  *
19
19
  * The strategy is:
20
- * 1) @@@
21
- * 2) @@@
20
+ * 1) First, match parameters by name where both available and expected.
21
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
22
22
  *
23
- * @throws {PipelineExecutionError} @@@
23
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
24
24
  * @private within the repository used in `createPipelineExecutor`
25
25
  */
26
26
  export declare function mapAvailableToExpectedParameters(options: MakeapAvailableToExpectedParametersOptions): Readonly<Record<string_parameter_name, string_parameter_value>>;
@@ -1,10 +1,11 @@
1
1
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
2
2
  /**
3
- * @@@
3
+ * Creates a deep clone of a PipelineJson object, copying all properties explicitly.
4
4
  *
5
- * Note: It is usefull @@@
5
+ * Note: It is useful for ensuring that modifications to the returned pipeline do not affect the original.
6
6
  *
7
- * @param pipeline
7
+ * @param pipeline The pipeline to clone.
8
+ * @returns A new PipelineJson object with the same properties as the input.
8
9
  * @public exported from `@promptbook/utils`
9
10
  */
10
11
  export declare function clonePipeline(pipeline: PipelineJson): PipelineJson;
@@ -1,7 +1,11 @@
1
1
  import type { WritableDeep } from 'type-fest';
2
2
  /**
3
- * @@@
3
+ * Creates a deep clone of the given object
4
4
  *
5
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
6
+ *
7
+ * @param objectValue The object to clone.
8
+ * @returns A deep, writable clone of the input object.
5
9
  * @public exported from `@promptbook/utils`
6
10
  */
7
11
  export declare function deepClone<TObject>(objectValue: TObject): WritableDeep<TObject>;
@@ -1,10 +1,10 @@
1
1
  import type { string_javascript_name } from '../../../types/typeAliases';
2
2
  import type { really_unknown } from '../../organization/really_unknown';
3
3
  /**
4
- * @@@
4
+ * Checks if the given value is a valid JavaScript identifier name.
5
5
  *
6
- * @param javascriptName @@@
7
- * @returns @@@
6
+ * @param javascriptName The value to check for JavaScript identifier validity.
7
+ * @returns `true` if the value is a valid JavaScript name, false otherwise.
8
8
  * @public exported from `@promptbook/utils`
9
9
  */
10
10
  export declare function isValidJavascriptName(javascriptName: really_unknown): javascriptName is string_javascript_name;
@@ -1,10 +1,11 @@
1
1
  import type { string_parameter_name } from '../../../types/typeAliases';
2
2
  /**
3
- * Function `validateParameterName` will @@@
3
+ * Function `validateParameterName` will normalize and validate a parameter name for use in pipelines.
4
+ * It removes diacritics, emojis, and quotes, normalizes to camelCase, and checks for reserved names and invalid characters.
4
5
  *
5
- * @param parameterName @@@
6
- * @returns @@@
7
- * @throws {ParseError} @@@
6
+ * @param parameterName The parameter name to validate and normalize.
7
+ * @returns The validated and normalized parameter name.
8
+ * @throws {ParseError} If the parameter name is empty, reserved, or contains invalid characters.
8
9
  * @private within the repository
9
10
  */
10
11
  export declare function validateParameterName(parameterName: string): string_parameter_name;
@@ -14,7 +14,8 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
14
14
  */
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
- * @@@
17
+ * Represents the version string of the Promptbook engine.
18
+ * It follows semantic versioning (e.g., `0.92.0-29`).
18
19
  *
19
20
  * @generated
20
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.92.0-3",
3
+ "version": "0.92.0-30",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -51,9 +51,10 @@
51
51
  "module": "./esm/index.es.js",
52
52
  "typings": "./esm/typings/src/_packages/openai.index.d.ts",
53
53
  "peerDependencies": {
54
- "@promptbook/core": "0.92.0-3"
54
+ "@promptbook/core": "0.92.0-30"
55
55
  },
56
56
  "dependencies": {
57
+ "bottleneck": "^2.19.5",
57
58
  "colors": "1.4.0",
58
59
  "crypto": "1.0.1",
59
60
  "openai": "4.63.0",
package/umd/index.umd.js CHANGED
@@ -1,13 +1,14 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('openai')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'openai'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.OpenAI));
5
- })(this, (function (exports, colors, spaceTrim, crypto, OpenAI) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'bottleneck', 'openai'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI));
5
+ })(this, (function (exports, colors, spaceTrim, crypto, Bottleneck, OpenAI) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
10
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
11
+ var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
11
12
  var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
12
13
 
13
14
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -24,7 +25,7 @@
24
25
  * @generated
25
26
  * @see https://github.com/webgptorg/promptbook
26
27
  */
27
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-3';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-30';
28
29
  /**
29
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -284,7 +285,7 @@
284
285
  const SMALL_NUMBER = 0.001;
285
286
  // <- TODO: [🧜‍♂️]
286
287
  /**
287
- * @@@
288
+ * Default settings for parsing and generating CSV files in Promptbook.
288
289
  *
289
290
  * @public exported from `@promptbook/core`
290
291
  */
@@ -294,6 +295,14 @@
294
295
  newline: '\n',
295
296
  skipEmptyLines: true,
296
297
  });
298
+ /**
299
+ * Default rate limits (requests per minute)
300
+ *
301
+ * Note: Adjust based on the provider tier you are have
302
+ *
303
+ * @public exported from `@promptbook/core`
304
+ */
305
+ const DEFAULT_MAX_REQUESTS_PER_MINUTE = 60;
297
306
  /**
298
307
  * Note: [💞] Ignore a discrepancy between file name and entity name
299
308
  * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
@@ -569,8 +578,12 @@
569
578
  */
570
579
 
571
580
  /**
572
- * @@@
581
+ * Creates a deep clone of the given object
582
+ *
583
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
573
584
  *
585
+ * @param objectValue The object to clone.
586
+ * @returns A deep, writable clone of the input object.
574
587
  * @public exported from `@promptbook/utils`
575
588
  */
576
589
  function deepClone(objectValue) {
@@ -632,13 +645,19 @@
632
645
  */
633
646
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
634
647
  /**
635
- * @@@
648
+ * Nonce which is used as string which is not occurring in normal text
649
+ *
650
+ * @private within the repository
651
+ */
652
+ const SALT_NONCE = 'ptbkghhewbvruets21t54et5';
653
+ /**
654
+ * Placeholder value indicating a parameter is missing its value.
636
655
  *
637
656
  * @private within the repository
638
657
  */
639
658
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
640
659
  /**
641
- * @@@
660
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
642
661
  *
643
662
  * @private within the repository
644
663
  */
@@ -801,10 +820,12 @@
801
820
  throw new PipelineExecutionError('Parameter is already opened or not closed');
802
821
  }
803
822
  if (parameters[parameterName] === undefined) {
823
+ console.log('!!! templateParameters 1', { parameterName, template, parameters });
804
824
  throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
805
825
  }
806
826
  let parameterValue = parameters[parameterName];
807
827
  if (parameterValue === undefined) {
828
+ console.log('!!! templateParameters 2', { parameterName, template, parameters });
808
829
  throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
809
830
  }
810
831
  parameterValue = valueToString(parameterValue);
@@ -1175,10 +1196,10 @@
1175
1196
  */
1176
1197
 
1177
1198
  /**
1178
- * @@@
1199
+ * Removes diacritic marks (accents) from characters in a string.
1179
1200
  *
1180
- * @param input @@@
1181
- * @returns @@@
1201
+ * @param input The string containing diacritics to be normalized.
1202
+ * @returns The string with diacritics removed or normalized.
1182
1203
  * @public exported from `@promptbook/utils`
1183
1204
  */
1184
1205
  function removeDiacritics(input) {
@@ -1229,14 +1250,18 @@
1229
1250
  /**
1230
1251
  * Make UncertainNumber
1231
1252
  *
1232
- * @param value
1253
+ * @param value value of the uncertain number, if `NaN` or `undefined`, it will be set to 0 and `isUncertain=true`
1254
+ * @param isUncertain if `true`, the value is uncertain, otherwise depends on the value
1233
1255
  *
1234
1256
  * @private utility for initializating UncertainNumber
1235
1257
  */
1236
- function uncertainNumber(value) {
1258
+ function uncertainNumber(value, isUncertain) {
1237
1259
  if (value === null || value === undefined || Number.isNaN(value)) {
1238
1260
  return UNCERTAIN_ZERO_VALUE;
1239
1261
  }
1262
+ if (isUncertain === true) {
1263
+ return { value, isUncertain };
1264
+ }
1240
1265
  return { value };
1241
1266
  }
1242
1267
 
@@ -1253,7 +1278,7 @@
1253
1278
  /**
1254
1279
  * List of available OpenAI models with pricing
1255
1280
  *
1256
- * Note: Done at 2024-05-20
1281
+ * Note: Done at 2025-05-06
1257
1282
  *
1258
1283
  * @see https://platform.openai.com/docs/models/
1259
1284
  * @see https://openai.com/api/pricing/
@@ -1282,7 +1307,7 @@
1282
1307
  modelDescription: 'Legacy completion model with strong performance on text generation tasks. Optimized for complex instructions and longer outputs.',
1283
1308
  pricing: {
1284
1309
  prompt: computeUsage(`$2.00 / 1M tokens`),
1285
- output: computeUsage(`$2.00 / 1M tokens`), // <- not sure
1310
+ output: computeUsage(`$2.00 / 1M tokens`),
1286
1311
  },
1287
1312
  },
1288
1313
  /**/
@@ -1424,8 +1449,8 @@
1424
1449
  modelName: 'gpt-3.5-turbo',
1425
1450
  modelDescription: 'Latest version of GPT-3.5 Turbo with improved performance and instruction following capabilities. Default 4K context window with options for 16K.',
1426
1451
  pricing: {
1427
- prompt: computeUsage(`$3.00 / 1M tokens`),
1428
- output: computeUsage(`$6.00 / 1M tokens`), // <- Not sure, refer to gpt-3.5-turbo in Fine-tuning models
1452
+ prompt: computeUsage(`$0.50 / 1M tokens`),
1453
+ output: computeUsage(`$1.50 / 1M tokens`),
1429
1454
  },
1430
1455
  },
1431
1456
  /**/
@@ -1449,7 +1474,7 @@
1449
1474
  modelDescription: 'Efficient legacy completion model with a good balance of performance and speed. Suitable for straightforward text generation tasks.',
1450
1475
  pricing: {
1451
1476
  prompt: computeUsage(`$0.40 / 1M tokens`),
1452
- output: computeUsage(`$0.40 / 1M tokens`), // <- Not sure
1477
+ output: computeUsage(`$0.40 / 1M tokens`),
1453
1478
  },
1454
1479
  },
1455
1480
  /**/
@@ -1503,7 +1528,7 @@
1503
1528
  modelDescription: 'Preview version of GPT-4 Turbo that points to the latest model version. Features improved instruction following, 128K token context window and lower latency.',
1504
1529
  pricing: {
1505
1530
  prompt: computeUsage(`$10.00 / 1M tokens`),
1506
- output: computeUsage(`$30.00 / 1M tokens`), // <- Not sure, just for gpt-4-turbo
1531
+ output: computeUsage(`$30.00 / 1M tokens`),
1507
1532
  },
1508
1533
  },
1509
1534
  /**/
@@ -1514,7 +1539,7 @@
1514
1539
  modelName: 'text-embedding-3-large',
1515
1540
  modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
1516
1541
  pricing: {
1517
- prompt: computeUsage(`$0.13 / 1M tokens`),
1542
+ prompt: computeUsage(`$0.13 / 1M tokens`),
1518
1543
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
1519
1544
  output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
1520
1545
  },
@@ -1607,8 +1632,8 @@
1607
1632
  modelName: 'gpt-4o-mini',
1608
1633
  modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
1609
1634
  pricing: {
1610
- prompt: computeUsage(`$3.00 / 1M tokens`),
1611
- output: computeUsage(`$9.00 / 1M tokens`),
1635
+ prompt: computeUsage(`$0.15 / 1M tokens`),
1636
+ output: computeUsage(`$0.60 / 1M tokens`),
1612
1637
  },
1613
1638
  },
1614
1639
  /**/
@@ -1654,10 +1679,10 @@
1654
1679
  modelVariant: 'CHAT',
1655
1680
  modelTitle: 'o1',
1656
1681
  modelName: 'o1',
1682
+ modelDescription: "OpenAI's advanced reasoning model focused on logic and problem-solving. Designed for complex analytical tasks with rigorous step-by-step reasoning. 128K context window.",
1657
1683
  pricing: {
1658
- prompt: computeUsage(`$3.00 / 1M tokens`),
1659
- output: computeUsage(`$12.00 / 1M tokens`),
1660
- // <- TODO: !! Unsure, check the pricing
1684
+ prompt: computeUsage(`$15.00 / 1M tokens`),
1685
+ output: computeUsage(`$60.00 / 1M tokens`),
1661
1686
  },
1662
1687
  },
1663
1688
  /**/
@@ -1666,7 +1691,7 @@
1666
1691
  modelVariant: 'CHAT',
1667
1692
  modelTitle: 'o3-mini',
1668
1693
  modelName: 'o3-mini',
1669
- modelDescription: 'Compact and efficient reasoning model specializing in problem-solving with a focus on research and analysis tasks.',
1694
+ modelDescription: 'Cost-effective reasoning model optimized for academic and scientific problem-solving. Efficient performance on STEM tasks with deep mathematical and scientific knowledge. 128K context window.',
1670
1695
  pricing: {
1671
1696
  prompt: computeUsage(`$3.00 / 1M tokens`),
1672
1697
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1729,20 +1754,39 @@
1729
1754
  resultContent, rawResponse) {
1730
1755
  var _a, _b;
1731
1756
  if (rawResponse.usage === undefined) {
1757
+ console.log('!!! computeOpenAiUsage', 'The usage is not defined in the response from OpenAI');
1732
1758
  throw new PipelineExecutionError('The usage is not defined in the response from OpenAI');
1733
1759
  }
1734
1760
  if (((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.prompt_tokens) === undefined) {
1761
+ console.log('!!! computeOpenAiUsage', 'In OpenAI response `usage.prompt_tokens` not defined');
1735
1762
  throw new PipelineExecutionError('In OpenAI response `usage.prompt_tokens` not defined');
1736
1763
  }
1737
1764
  const inputTokens = rawResponse.usage.prompt_tokens;
1738
1765
  const outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completion_tokens) || 0;
1739
- const modelInfo = OPENAI_MODELS.find((model) => model.modelName === rawResponse.model);
1766
+ let isUncertain = false;
1767
+ let modelInfo = OPENAI_MODELS.find((model) => model.modelName === rawResponse.model);
1768
+ if (modelInfo === undefined) {
1769
+ // Note: Model is not in the list of known models, fallback to the family of the models and mark price as uncertain
1770
+ modelInfo = OPENAI_MODELS.find((model) => (rawResponse.model || SALT_NONCE).startsWith(model.modelName));
1771
+ if (modelInfo !== undefined) {
1772
+ isUncertain = true;
1773
+ }
1774
+ }
1775
+ console.log('!!! computeOpenAiUsage', {
1776
+ inputTokens,
1777
+ outputTokens,
1778
+ rawResponse,
1779
+ 'rawResponse.model': rawResponse.model,
1780
+ OPENAI_MODELS,
1781
+ resultContent,
1782
+ modelInfo,
1783
+ });
1740
1784
  let price;
1741
1785
  if (modelInfo === undefined || modelInfo.pricing === undefined) {
1742
1786
  price = uncertainNumber();
1743
1787
  }
1744
1788
  else {
1745
- price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
1789
+ price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output, isUncertain);
1746
1790
  }
1747
1791
  return {
1748
1792
  price,
@@ -1777,6 +1821,10 @@
1777
1821
  * OpenAI API client.
1778
1822
  */
1779
1823
  this.client = null;
1824
+ // TODO: Allow configuring rate limits via options
1825
+ this.limiter = new Bottleneck__default["default"]({
1826
+ minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
1827
+ });
1780
1828
  }
1781
1829
  get title() {
1782
1830
  return 'OpenAI';
@@ -1880,7 +1928,9 @@
1880
1928
  if (this.options.isVerbose) {
1881
1929
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1882
1930
  }
1883
- const rawResponse = await client.chat.completions.create(rawRequest).catch((error) => {
1931
+ const rawResponse = await this.limiter
1932
+ .schedule(() => client.chat.completions.create(rawRequest))
1933
+ .catch((error) => {
1884
1934
  assertsError(error);
1885
1935
  if (this.options.isVerbose) {
1886
1936
  console.info(colors__default["default"].bgRed('error'), error);
@@ -1957,7 +2007,9 @@
1957
2007
  if (this.options.isVerbose) {
1958
2008
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1959
2009
  }
1960
- const rawResponse = await client.completions.create(rawRequest).catch((error) => {
2010
+ const rawResponse = await this.limiter
2011
+ .schedule(() => client.completions.create(rawRequest))
2012
+ .catch((error) => {
1961
2013
  assertsError(error);
1962
2014
  if (this.options.isVerbose) {
1963
2015
  console.info(colors__default["default"].bgRed('error'), error);
@@ -2021,7 +2073,9 @@
2021
2073
  if (this.options.isVerbose) {
2022
2074
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
2023
2075
  }
2024
- const rawResponse = await client.embeddings.create(rawRequest).catch((error) => {
2076
+ const rawResponse = await this.limiter
2077
+ .schedule(() => client.embeddings.create(rawRequest))
2078
+ .catch((error) => {
2025
2079
  assertsError(error);
2026
2080
  if (this.options.isVerbose) {
2027
2081
  console.info(colors__default["default"].bgRed('error'), error);
@@ -2119,6 +2173,7 @@
2119
2173
  constructor(options) {
2120
2174
  super(options);
2121
2175
  this.assistantId = options.assistantId;
2176
+ // TODO: [👱] Make limiter same as in `OpenAiExecutionTools`
2122
2177
  }
2123
2178
  get title() {
2124
2179
  return 'OpenAI Assistant';
@@ -2310,7 +2365,8 @@
2310
2365
  */
2311
2366
 
2312
2367
  /**
2313
- * @@@
2368
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
2369
+ * regardless of the JavaScript environment in which the code is running
2314
2370
  *
2315
2371
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
2316
2372
  *
@@ -2321,10 +2377,10 @@
2321
2377
  }
2322
2378
 
2323
2379
  /**
2324
- * @@@
2380
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2325
2381
  *
2326
- * @param text @@@
2327
- * @returns @@@
2382
+ * @param text The text string to be converted to SCREAMING_CASE format.
2383
+ * @returns The normalized text in SCREAMING_CASE format.
2328
2384
  * @example 'HELLO_WORLD'
2329
2385
  * @example 'I_LOVE_PROMPTBOOK'
2330
2386
  * @public exported from `@promptbook/utils`
@@ -2376,10 +2432,10 @@
2376
2432
  */
2377
2433
 
2378
2434
  /**
2379
- * @@@
2435
+ * Normalizes a text string to snake_case format.
2380
2436
  *
2381
- * @param text @@@
2382
- * @returns @@@
2437
+ * @param text The text string to be converted to snake_case format.
2438
+ * @returns The normalized text in snake_case format.
2383
2439
  * @example 'hello_world'
2384
2440
  * @example 'i_love_promptbook'
2385
2441
  * @public exported from `@promptbook/utils`
@@ -2389,11 +2445,11 @@
2389
2445
  }
2390
2446
 
2391
2447
  /**
2392
- * Register is @@@
2448
+ * Global registry for storing and managing registered entities of a given type.
2393
2449
  *
2394
2450
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
2395
2451
  *
2396
- * @private internal utility, exported are only signleton instances of this class
2452
+ * @private internal utility, exported are only singleton instances of this class
2397
2453
  */
2398
2454
  class $Register {
2399
2455
  constructor(registerName) {
@@ -2437,10 +2493,10 @@
2437
2493
  }
2438
2494
 
2439
2495
  /**
2440
- * @@@
2496
+ * Register for LLM tools.
2441
2497
  *
2442
2498
  * Note: `$` is used to indicate that this interacts with the global scope
2443
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2499
+ * @singleton Only one instance of each register is created per build, but there can be more instances across different builds or environments.
2444
2500
  * @public exported from `@promptbook/core`
2445
2501
  */
2446
2502
  const $llmToolsRegister = new $Register('llm_execution_tools_constructors');
@@ -2459,9 +2515,9 @@
2459
2515
  */
2460
2516
  const _OpenAiRegistration = $llmToolsRegister.register(createOpenAiExecutionTools);
2461
2517
  /**
2462
- * @@@ registration2
2518
+ * Registration of the OpenAI Assistant provider
2463
2519
  *
2464
- * Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
2520
+ * Note: [🏐] Configurations registrations are done in register-constructor.ts BUT constructor register-constructor.ts
2465
2521
  *
2466
2522
  * @public exported from `@promptbook/openai`
2467
2523
  * @public exported from `@promptbook/wizzard`