fix: update buildApiHandler return type to support prompt enhancement #6530
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the "Failed to enhance prompt" error reported in #6529. The issue was that the
buildApiHandlerfunction was returning anApiHandlertype, but many API providers actually implement bothApiHandlerandSingleCompletionHandlerinterfaces. ThecompletePromptmethod needed for prompt enhancement is part of theSingleCompletionHandlerinterface.Changes
buildApiHandlerreturn type fromApiHandlertoApiHandler & Partial<SingleCompletionHandler>singleCompletionHandlerto check for the existence ofcompletePromptmethod using optional chainingcompletePromptmethod to properly expose it for prompt enhancementTesting
npx vitest run src/utils/__tests__/enhance-prompt.spec.ts- all tests passnpx vitest run src/api/providers/__tests__/*.spec.ts- all provider tests passRelated Issue
Fixes #6529
Important
Update
buildApiHandlerreturn type and modifysingleCompletionHandlerto fix prompt enhancement error.buildApiHandlerreturn type toApiHandler & Partial<SingleCompletionHandler>inindex.tsto supportcompletePromptmethod.singleCompletionHandlerinsingle-completion-handler.tsto use optional chaining forcompletePromptmethod check.enhance-prompt.spec.tsand provider tests.This description was created by
for 5675471. You can customize this summary. It will automatically update as commits are pushed.