mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 20:31:37 -05:00
refactor: generalize prompt enhancement into single completion handler
- Rename enhance-prompt.ts to single-completion-handler.ts for better clarity - Refactor enhancement logic to be more generic and reusable - Update prompt template handling to use template literals - Adjust tests and imports accordingly
This commit is contained in:
24
src/utils/single-completion-handler.ts
Normal file
24
src/utils/single-completion-handler.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { ApiConfiguration } from "../shared/api"
|
||||
import { buildApiHandler, SingleCompletionHandler } from "../api"
|
||||
|
||||
/**
|
||||
* Enhances a prompt using the configured API without creating a full Cline instance or task history.
|
||||
* This is a lightweight alternative that only uses the API's completion functionality.
|
||||
*/
|
||||
export async function singleCompletionHandler(apiConfiguration: ApiConfiguration, promptText: string): Promise<string> {
|
||||
if (!promptText) {
|
||||
throw new Error("No prompt text provided")
|
||||
}
|
||||
if (!apiConfiguration || !apiConfiguration.apiProvider) {
|
||||
throw new Error("No valid API configuration provided")
|
||||
}
|
||||
|
||||
const handler = buildApiHandler(apiConfiguration)
|
||||
|
||||
// Check if handler supports single completions
|
||||
if (!("completePrompt" in handler)) {
|
||||
throw new Error("The selected API provider does not support prompt enhancement")
|
||||
}
|
||||
|
||||
return (handler as SingleCompletionHandler).completePrompt(promptText)
|
||||
}
|
||||
Reference in New Issue
Block a user