* Enhances a message prompt using the configured AI provider * @param options Configuration options for message enhancement * @returns Enhanced message result with success status
(options: MessageEnhancerOptions)
| 32 | * @returns Enhanced message result with success status |
| 33 | */ |
| 34 | static async enhanceMessage(options: MessageEnhancerOptions): Promise<MessageEnhancerResult> { |
| 35 | try { |
| 36 | const { |
| 37 | text, |
| 38 | apiConfiguration, |
| 39 | customSupportPrompts, |
| 40 | listApiConfigMeta, |
| 41 | enhancementApiConfigId, |
| 42 | includeTaskHistoryInEnhance, |
| 43 | currentClineMessages, |
| 44 | providerSettingsManager, |
| 45 | } = options |
| 46 | |
| 47 | // Determine which API configuration to use |
| 48 | let configToUse: ProviderSettings = apiConfiguration |
| 49 | |
| 50 | // Try to get enhancement config first, fall back to current config |
| 51 | if (enhancementApiConfigId && listApiConfigMeta.find(({ id }) => id === enhancementApiConfigId)) { |
| 52 | const { name: _, ...providerSettings } = await providerSettingsManager.getProfile({ |
| 53 | id: enhancementApiConfigId, |
| 54 | }) |
| 55 | |
| 56 | if (providerSettings.apiProvider) { |
| 57 | configToUse = providerSettings |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Prepare the prompt to enhance |
| 62 | let promptToEnhance = text |
| 63 | |
| 64 | // Include task history if enabled and available |
| 65 | if (includeTaskHistoryInEnhance && currentClineMessages && currentClineMessages.length > 0) { |
| 66 | const taskHistory = this.extractTaskHistory(currentClineMessages) |
| 67 | if (taskHistory) { |
| 68 | promptToEnhance = `${text}\n\nUse the following previous conversation context as needed:\n${taskHistory}` |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Create the enhancement prompt using the support prompt system |
| 73 | const enhancementPrompt = supportPrompt.create( |
| 74 | "ENHANCE", |
| 75 | { userInput: promptToEnhance }, |
| 76 | customSupportPrompts, |
| 77 | ) |
| 78 | |
| 79 | // Call the single completion handler to get the enhanced prompt |
| 80 | const enhancedText = await singleCompletionHandler(configToUse, enhancementPrompt) |
| 81 | |
| 82 | return { |
| 83 | success: true, |
| 84 | enhancedText, |
| 85 | } |
| 86 | } catch (error) { |
| 87 | return { |
| 88 | success: false, |
| 89 | error: error instanceof Error ? error.message : String(error), |
| 90 | } |
| 91 | } |
no test coverage detected