2
0
Эх сурвалжийг харах

refactor: require native tool call for Responses API (#7953)

Add validation to ensure native tool calling is enabled when using
OpenAI Responses API format. Previously, the code would silently fall
back to completion stream when tools were not provided, which could
lead to unexpected behavior.

- Add explicit error when tools are missing for Responses API format
- Update tools parameter type to non-optional in createResponseStream
Bee 3 долоо хоног өмнө
parent
commit
34bb95e04e

+ 5 - 2
src/core/api/providers/openai-native.ts

@@ -64,7 +64,10 @@ export class OpenAiNativeHandler implements ApiHandler {
 	@withRetry()
 	async *createMessage(systemPrompt: string, messages: ClineStorageMessage[], tools?: ChatCompletionTool[]): ApiStream {
 		// Responses API requires tool format to be set to OPENAI_RESPONSES with native tools calling enabled
-		if (tools?.length && this.getModel()?.info?.apiFormat === ApiFormat.OPENAI_RESPONSES) {
+		if (this.getModel()?.info?.apiFormat === ApiFormat.OPENAI_RESPONSES) {
+			if (!tools?.length) {
+				throw new Error("Native Tool Call must be enabled in your setting for OpenAI Responses API")
+			}
 			yield* this.createResponseStream(systemPrompt, messages, tools)
 		} else {
 			yield* this.createCompletionStream(systemPrompt, messages, tools)
@@ -156,7 +159,7 @@ export class OpenAiNativeHandler implements ApiHandler {
 	private async *createResponseStream(
 		systemPrompt: string,
 		messages: ClineStorageMessage[],
-		tools?: ChatCompletionTool[],
+		tools: ChatCompletionTool[],
 	): ApiStream {
 		const client = this.ensureClient()
 		const model = this.getModel()