single-completion-handler.ts 924 B

123456789101112131415161718192021222324
  1. import { ApiConfiguration } from "../shared/api"
  2. import { buildApiHandler, SingleCompletionHandler } from "../api"
  3. /**
  4. * Enhances a prompt using the configured API without creating a full Cline instance or task history.
  5. * This is a lightweight alternative that only uses the API's completion functionality.
  6. */
  7. export async function singleCompletionHandler(apiConfiguration: ApiConfiguration, promptText: string): Promise<string> {
  8. if (!promptText) {
  9. throw new Error("No prompt text provided")
  10. }
  11. if (!apiConfiguration || !apiConfiguration.apiProvider) {
  12. throw new Error("No valid API configuration provided")
  13. }
  14. const handler = buildApiHandler(apiConfiguration)
  15. // Check if handler supports single completions
  16. if (!("completePrompt" in handler)) {
  17. throw new Error("The selected API provider does not support prompt enhancement")
  18. }
  19. return (handler as SingleCompletionHandler).completePrompt(promptText)
  20. }