@promptbook/openai 0.102.0-5 → 0.102.0-7

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 (98) hide show
  1. package/esm/index.es.js +121 -56
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/books/index.d.ts +81 -0
  4. package/esm/typings/src/_packages/components.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/markdown-utils.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +8 -6
  7. package/esm/typings/src/_packages/utils.index.d.ts +12 -14
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +1 -1
  9. package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +1 -1
  10. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +1 -1
  11. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +1 -1
  12. package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +1 -1
  13. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +1 -5
  14. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +27 -0
  15. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +13 -6
  16. package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +7 -0
  17. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +1 -1
  18. package/esm/typings/src/book-components/Chat/MockedChat/MockedChat.d.ts +1 -1
  19. package/esm/typings/src/book-components/Chat/MockedChat/constants.d.ts +1 -1
  20. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
  21. package/esm/typings/src/book-components/Chat/save/_common/getChatSaveFormatDefinitions.d.ts +2 -2
  22. package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
  23. package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +1 -1
  24. package/esm/typings/src/execution/execution-report/countWorkingDuration.d.ts +1 -1
  25. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +1 -1
  26. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +1 -1
  27. package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +1 -2
  28. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
  29. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
  30. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/agent/register-configuration.d.ts +1 -1
  32. package/esm/typings/src/llm-providers/agent/register-constructor.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -1
  35. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +1 -1
  39. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -1
  40. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -1
  41. package/esm/typings/src/llm-providers/ollama/register-configuration.d.ts +1 -1
  42. package/esm/typings/src/llm-providers/ollama/register-constructor.d.ts +1 -1
  43. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -3
  44. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +0 -4
  45. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +1 -1
  46. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +1 -1
  47. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +1 -1
  48. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  49. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +1 -1
  50. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +1 -1
  51. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -4
  52. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +1 -1
  53. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -1
  54. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
  55. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -1
  56. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
  57. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -1
  58. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
  59. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +1 -1
  60. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +1 -1
  61. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -1
  62. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
  63. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -1
  64. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
  65. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +6 -6
  66. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
  67. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +1 -1
  68. package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +1 -1
  69. package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
  70. package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +1 -1
  71. package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +1 -1
  72. package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +1 -1
  73. package/esm/typings/src/utils/{trimCodeBlock.d.ts → markdown/trimCodeBlock.d.ts} +1 -1
  74. package/esm/typings/src/utils/{trimEndOfCodeBlock.d.ts → markdown/trimEndOfCodeBlock.d.ts} +1 -1
  75. package/esm/typings/src/utils/{$Register.d.ts → misc/$Register.d.ts} +2 -2
  76. package/esm/typings/src/utils/{$getCurrentDate.d.ts → misc/$getCurrentDate.d.ts} +1 -1
  77. package/esm/typings/src/utils/{arrayableToArray.d.ts → misc/arrayableToArray.d.ts} +1 -1
  78. package/esm/typings/src/utils/misc/debounce.d.ts +5 -0
  79. package/esm/typings/src/utils/{emojis.d.ts → misc/emojis.d.ts} +1 -1
  80. package/esm/typings/src/utils/misc/injectCssModuleIntoShadowRoot.d.ts +20 -0
  81. package/esm/typings/src/version.d.ts +1 -1
  82. package/package.json +2 -2
  83. package/umd/index.umd.js +121 -56
  84. package/umd/index.umd.js.map +1 -1
  85. package/esm/typings/src/book-components/BookEditor/injectCssModuleIntoShadowRoot.d.ts +0 -11
  86. package/esm/typings/src/book-components/BookEditor/utils.d.ts +0 -8
  87. /package/esm/typings/src/utils/{trimCodeBlock.test.d.ts → markdown/trimCodeBlock.test.d.ts} +0 -0
  88. /package/esm/typings/src/utils/{trimEndOfCodeBlock.test.d.ts → markdown/trimEndOfCodeBlock.test.d.ts} +0 -0
  89. /package/esm/typings/src/utils/{FromtoItems.d.ts → misc/FromtoItems.d.ts} +0 -0
  90. /package/esm/typings/src/utils/{arrayableToArray.test.d.ts → misc/arrayableToArray.test.d.ts} +0 -0
  91. /package/esm/typings/src/utils/{parseNumber.d.ts → misc/parseNumber.d.ts} +0 -0
  92. /package/esm/typings/src/utils/{parseNumber.test.d.ts → misc/parseNumber.test.d.ts} +0 -0
  93. /package/esm/typings/src/utils/{removeEmojis.d.ts → normalization/removeEmojis.d.ts} +0 -0
  94. /package/esm/typings/src/utils/{removeEmojis.test.d.ts → normalization/removeEmojis.test.d.ts} +0 -0
  95. /package/esm/typings/src/utils/{removeQuotes.d.ts → normalization/removeQuotes.d.ts} +0 -0
  96. /package/esm/typings/src/utils/{removeQuotes.test.d.ts → normalization/removeQuotes.test.d.ts} +0 -0
  97. /package/esm/typings/src/utils/{unwrapResult.d.ts → normalization/unwrapResult.d.ts} +0 -0
  98. /package/esm/typings/src/utils/{unwrapResult.test.d.ts → normalization/unwrapResult.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
19
19
  * @generated
20
20
  * @see https://github.com/webgptorg/promptbook
21
21
  */
22
- const PROMPTBOOK_ENGINE_VERSION = '0.102.0-5';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.102.0-7';
23
23
  /**
24
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
25
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2004,6 +2004,7 @@ function isUnsupportedParameterError(error) {
2004
2004
  * @public exported from `@promptbook/openai`
2005
2005
  */
2006
2006
  class OpenAiCompatibleExecutionTools {
2007
+ // Removed retriedUnsupportedParameters and attemptHistory instance fields
2007
2008
  /**
2008
2009
  * Creates OpenAI compatible Execution Tools.
2009
2010
  *
@@ -2015,10 +2016,6 @@ class OpenAiCompatibleExecutionTools {
2015
2016
  * OpenAI API client.
2016
2017
  */
2017
2018
  this.client = null;
2018
- /**
2019
- * Tracks models and parameters that have already been retried to prevent infinite loops
2020
- */
2021
- this.retriedUnsupportedParameters = new Set();
2022
2019
  // TODO: Allow configuring rate limits via options
2023
2020
  this.limiter = new Bottleneck({
2024
2021
  minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
@@ -2080,12 +2077,16 @@ class OpenAiCompatibleExecutionTools {
2080
2077
  * Calls OpenAI compatible API to use a chat model.
2081
2078
  */
2082
2079
  async callChatModel(prompt) {
2083
- return this.callChatModelWithRetry(prompt, prompt.modelRequirements);
2080
+ // Deep clone prompt and modelRequirements to avoid mutation across calls
2081
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
2082
+ // Use local Set for retried parameters to ensure independence and thread safety
2083
+ const retriedUnsupportedParameters = new Set();
2084
+ return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
2084
2085
  }
2085
2086
  /**
2086
2087
  * Internal method that handles parameter retry for chat model calls
2087
2088
  */
2088
- async callChatModelWithRetry(prompt, currentModelRequirements) {
2089
+ async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
2089
2090
  var _a;
2090
2091
  if (this.options.isVerbose) {
2091
2092
  console.info(`💬 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
@@ -2192,6 +2193,17 @@ class OpenAiCompatibleExecutionTools {
2192
2193
  assertsError(error);
2193
2194
  // Check if this is an unsupported parameter error
2194
2195
  if (!isUnsupportedParameterError(error)) {
2196
+ // If we have attemptStack, include it in the error message
2197
+ if (attemptStack.length > 0) {
2198
+ throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
2199
+ attemptStack
2200
+ .map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
2201
+ (a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
2202
+ `, Error: ${a.errorMessage}` +
2203
+ (a.stripped ? ' (stripped and retried)' : ''))
2204
+ .join('\n') +
2205
+ `\nFinal error: ${error.message}`);
2206
+ }
2195
2207
  throw error;
2196
2208
  }
2197
2209
  // Parse which parameter is unsupported
@@ -2204,34 +2216,54 @@ class OpenAiCompatibleExecutionTools {
2204
2216
  }
2205
2217
  // Create a unique key for this model + parameter combination to prevent infinite loops
2206
2218
  const retryKey = `${modelName}-${unsupportedParameter}`;
2207
- if (this.retriedUnsupportedParameters.has(retryKey)) {
2208
- // Already retried this parameter, throw the error
2209
- if (this.options.isVerbose) {
2210
- console.warn(colors.bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
2211
- }
2212
- throw error;
2219
+ if (retriedUnsupportedParameters.has(retryKey)) {
2220
+ // Already retried this parameter, throw the error with attemptStack
2221
+ attemptStack.push({
2222
+ modelName,
2223
+ unsupportedParameter,
2224
+ errorMessage: error.message,
2225
+ stripped: true,
2226
+ });
2227
+ throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
2228
+ attemptStack
2229
+ .map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
2230
+ (a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
2231
+ `, Error: ${a.errorMessage}` +
2232
+ (a.stripped ? ' (stripped and retried)' : ''))
2233
+ .join('\n') +
2234
+ `\nFinal error: ${error.message}`);
2213
2235
  }
2214
2236
  // Mark this parameter as retried
2215
- this.retriedUnsupportedParameters.add(retryKey);
2237
+ retriedUnsupportedParameters.add(retryKey);
2216
2238
  // Log warning in verbose mode
2217
2239
  if (this.options.isVerbose) {
2218
2240
  console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
2219
2241
  }
2242
+ // Add to attemptStack
2243
+ attemptStack.push({
2244
+ modelName,
2245
+ unsupportedParameter,
2246
+ errorMessage: error.message,
2247
+ stripped: true,
2248
+ });
2220
2249
  // Remove the unsupported parameter and retry
2221
2250
  const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
2222
- return this.callChatModelWithRetry(prompt, modifiedModelRequirements);
2251
+ return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
2223
2252
  }
2224
2253
  }
2225
2254
  /**
2226
2255
  * Calls OpenAI API to use a complete model.
2227
2256
  */
2228
2257
  async callCompletionModel(prompt) {
2229
- return this.callCompletionModelWithRetry(prompt, prompt.modelRequirements);
2258
+ // Deep clone prompt and modelRequirements to avoid mutation across calls
2259
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
2260
+ const retriedUnsupportedParameters = new Set();
2261
+ return this.callCompletionModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
2230
2262
  }
2231
2263
  /**
2232
2264
  * Internal method that handles parameter retry for completion model calls
2233
2265
  */
2234
- async callCompletionModelWithRetry(prompt, currentModelRequirements) {
2266
+ async callCompletionModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
2235
2267
  var _a;
2236
2268
  if (this.options.isVerbose) {
2237
2269
  console.info(`🖋 ${this.title} callCompletionModel call`, { prompt, currentModelRequirements });
@@ -2247,8 +2279,6 @@ class OpenAiCompatibleExecutionTools {
2247
2279
  model: modelName,
2248
2280
  max_tokens: currentModelRequirements.maxTokens,
2249
2281
  temperature: currentModelRequirements.temperature,
2250
- // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
2251
- // <- Note: [🧆]
2252
2282
  };
2253
2283
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
2254
2284
  const rawRequest = {
@@ -2278,7 +2308,6 @@ class OpenAiCompatibleExecutionTools {
2278
2308
  throw new PipelineExecutionError(`No choises from ${this.title}`);
2279
2309
  }
2280
2310
  if (rawResponse.choices.length > 1) {
2281
- // TODO: This should be maybe only warning
2282
2311
  throw new PipelineExecutionError(`More than one choise from ${this.title}`);
2283
2312
  }
2284
2313
  const resultContent = rawResponse.choices[0].text;
@@ -2298,17 +2327,24 @@ class OpenAiCompatibleExecutionTools {
2298
2327
  rawPromptContent,
2299
2328
  rawRequest,
2300
2329
  rawResponse,
2301
- // <- [🗯]
2302
2330
  },
2303
2331
  });
2304
2332
  }
2305
2333
  catch (error) {
2306
2334
  assertsError(error);
2307
- // Check if this is an unsupported parameter error
2308
2335
  if (!isUnsupportedParameterError(error)) {
2336
+ if (attemptStack.length > 0) {
2337
+ throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
2338
+ attemptStack
2339
+ .map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
2340
+ (a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
2341
+ `, Error: ${a.errorMessage}` +
2342
+ (a.stripped ? ' (stripped and retried)' : ''))
2343
+ .join('\n') +
2344
+ `\nFinal error: ${error.message}`);
2345
+ }
2309
2346
  throw error;
2310
2347
  }
2311
- // Parse which parameter is unsupported
2312
2348
  const unsupportedParameter = parseUnsupportedParameterError(error.message);
2313
2349
  if (!unsupportedParameter) {
2314
2350
  if (this.options.isVerbose) {
@@ -2316,42 +2352,55 @@ class OpenAiCompatibleExecutionTools {
2316
2352
  }
2317
2353
  throw error;
2318
2354
  }
2319
- // Create a unique key for this model + parameter combination to prevent infinite loops
2320
2355
  const retryKey = `${modelName}-${unsupportedParameter}`;
2321
- if (this.retriedUnsupportedParameters.has(retryKey)) {
2322
- // Already retried this parameter, throw the error
2323
- if (this.options.isVerbose) {
2324
- console.warn(colors.bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
2325
- }
2326
- throw error;
2356
+ if (retriedUnsupportedParameters.has(retryKey)) {
2357
+ attemptStack.push({
2358
+ modelName,
2359
+ unsupportedParameter,
2360
+ errorMessage: error.message,
2361
+ stripped: true,
2362
+ });
2363
+ throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
2364
+ attemptStack
2365
+ .map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
2366
+ (a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
2367
+ `, Error: ${a.errorMessage}` +
2368
+ (a.stripped ? ' (stripped and retried)' : ''))
2369
+ .join('\n') +
2370
+ `\nFinal error: ${error.message}`);
2327
2371
  }
2328
- // Mark this parameter as retried
2329
- this.retriedUnsupportedParameters.add(retryKey);
2330
- // Log warning in verbose mode
2372
+ retriedUnsupportedParameters.add(retryKey);
2331
2373
  if (this.options.isVerbose) {
2332
2374
  console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
2333
2375
  }
2334
- // Remove the unsupported parameter and retry
2376
+ attemptStack.push({
2377
+ modelName,
2378
+ unsupportedParameter,
2379
+ errorMessage: error.message,
2380
+ stripped: true,
2381
+ });
2335
2382
  const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
2336
- return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements);
2383
+ return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
2337
2384
  }
2338
2385
  }
2339
2386
  /**
2340
2387
  * Calls OpenAI compatible API to use a embedding model
2341
2388
  */
2342
2389
  async callEmbeddingModel(prompt) {
2343
- return this.callEmbeddingModelWithRetry(prompt, prompt.modelRequirements);
2390
+ // Deep clone prompt and modelRequirements to avoid mutation across calls
2391
+ const clonedPrompt = JSON.parse(JSON.stringify(prompt));
2392
+ const retriedUnsupportedParameters = new Set();
2393
+ return this.callEmbeddingModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
2344
2394
  }
2345
2395
  /**
2346
2396
  * Internal method that handles parameter retry for embedding model calls
2347
2397
  */
2348
- async callEmbeddingModelWithRetry(prompt, currentModelRequirements) {
2398
+ async callEmbeddingModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
2349
2399
  if (this.options.isVerbose) {
2350
2400
  console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
2351
2401
  }
2352
2402
  const { content, parameters } = prompt;
2353
2403
  const client = await this.getClient();
2354
- // TODO: [☂] Use here more modelRequirements
2355
2404
  if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
2356
2405
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
2357
2406
  }
@@ -2383,9 +2432,7 @@ class OpenAiCompatibleExecutionTools {
2383
2432
  throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
2384
2433
  }
2385
2434
  const resultContent = rawResponse.data[0].embedding;
2386
- const usage = this.computeUsage(content || '', '',
2387
- // <- Note: Embedding does not have result content
2388
- rawResponse);
2435
+ const usage = this.computeUsage(content || '', '', rawResponse);
2389
2436
  return exportJson({
2390
2437
  name: 'promptResult',
2391
2438
  message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
@@ -2401,17 +2448,24 @@ class OpenAiCompatibleExecutionTools {
2401
2448
  rawPromptContent,
2402
2449
  rawRequest,
2403
2450
  rawResponse,
2404
- // <- [🗯]
2405
2451
  },
2406
2452
  });
2407
2453
  }
2408
2454
  catch (error) {
2409
2455
  assertsError(error);
2410
- // Check if this is an unsupported parameter error
2411
2456
  if (!isUnsupportedParameterError(error)) {
2457
+ if (attemptStack.length > 0) {
2458
+ throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
2459
+ attemptStack
2460
+ .map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
2461
+ (a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
2462
+ `, Error: ${a.errorMessage}` +
2463
+ (a.stripped ? ' (stripped and retried)' : ''))
2464
+ .join('\n') +
2465
+ `\nFinal error: ${error.message}`);
2466
+ }
2412
2467
  throw error;
2413
2468
  }
2414
- // Parse which parameter is unsupported
2415
2469
  const unsupportedParameter = parseUnsupportedParameterError(error.message);
2416
2470
  if (!unsupportedParameter) {
2417
2471
  if (this.options.isVerbose) {
@@ -2419,24 +2473,35 @@ class OpenAiCompatibleExecutionTools {
2419
2473
  }
2420
2474
  throw error;
2421
2475
  }
2422
- // Create a unique key for this model + parameter combination to prevent infinite loops
2423
2476
  const retryKey = `${modelName}-${unsupportedParameter}`;
2424
- if (this.retriedUnsupportedParameters.has(retryKey)) {
2425
- // Already retried this parameter, throw the error
2426
- if (this.options.isVerbose) {
2427
- console.warn(colors.bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
2428
- }
2429
- throw error;
2477
+ if (retriedUnsupportedParameters.has(retryKey)) {
2478
+ attemptStack.push({
2479
+ modelName,
2480
+ unsupportedParameter,
2481
+ errorMessage: error.message,
2482
+ stripped: true,
2483
+ });
2484
+ throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
2485
+ attemptStack
2486
+ .map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
2487
+ (a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
2488
+ `, Error: ${a.errorMessage}` +
2489
+ (a.stripped ? ' (stripped and retried)' : ''))
2490
+ .join('\n') +
2491
+ `\nFinal error: ${error.message}`);
2430
2492
  }
2431
- // Mark this parameter as retried
2432
- this.retriedUnsupportedParameters.add(retryKey);
2433
- // Log warning in verbose mode
2493
+ retriedUnsupportedParameters.add(retryKey);
2434
2494
  if (this.options.isVerbose) {
2435
2495
  console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
2436
2496
  }
2437
- // Remove the unsupported parameter and retry
2497
+ attemptStack.push({
2498
+ modelName,
2499
+ unsupportedParameter,
2500
+ errorMessage: error.message,
2501
+ stripped: true,
2502
+ });
2438
2503
  const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
2439
- return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements);
2504
+ return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
2440
2505
  }
2441
2506
  }
2442
2507
  // <- Note: [🤖] callXxxModel