@@ -28,6 +28,9 @@ export type OpenAiNativeModel = ReturnType<OpenAiNativeHandler["getModel"]>
28
28
29
29
// GPT-5 specific types
30
30
31
+ // Constants for model identification
32
+ const GPT5_MODEL_PREFIX = "gpt-5"
33
+
31
34
export class OpenAiNativeHandler extends BaseProvider implements SingleCompletionHandler {
32
35
protected options : ApiHandlerOptions
33
36
private client : OpenAI
@@ -155,7 +158,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
155
158
}
156
159
157
160
// Format input and capture continuity id
158
- const { formattedInput, previousResponseId } = this . prepareStructuredInput ( systemPrompt , messages , metadata )
161
+ const { formattedInput, previousResponseId } = this . prepareResponsesApiInput ( systemPrompt , messages , metadata )
159
162
const requestPreviousResponseId = effectivePreviousResponseId || previousResponseId
160
163
161
164
// Create a new promise for this request's response ID
@@ -222,7 +225,9 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
222
225
...( model . info . supportsTemperature !== false && {
223
226
temperature :
224
227
this . options . modelTemperature ??
225
- ( model . id . startsWith ( "gpt-5" ) ? GPT5_DEFAULT_TEMPERATURE : OPENAI_NATIVE_DEFAULT_TEMPERATURE ) ,
228
+ ( model . id . startsWith ( GPT5_MODEL_PREFIX )
229
+ ? GPT5_DEFAULT_TEMPERATURE
230
+ : OPENAI_NATIVE_DEFAULT_TEMPERATURE ) ,
226
231
} ) ,
227
232
// Explicitly include the calculated max output tokens.
228
233
// Use the per-request reserved output computed by Roo (params.maxTokens from getModelParams).
@@ -261,7 +266,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
261
266
if ( is400Error && requestBody . previous_response_id && isPreviousResponseError ) {
262
267
// Log the error and retry without the previous_response_id
263
268
console . warn (
264
- `[GPT-5 ] Previous response ID not found (${ requestBody . previous_response_id } ), retrying without it` ,
269
+ `[Responses API ] Previous response ID not found (${ requestBody . previous_response_id } ), retrying without it` ,
265
270
)
266
271
267
272
// Remove the problematic previous_response_id and retry
@@ -301,8 +306,8 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
301
306
}
302
307
}
303
308
304
- private formatStructuredInput ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : any {
305
- // Format the conversation for the Responses API using structured format
309
+ private formatFullConversation ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : any {
310
+ // Format the entire conversation history for the Responses API using structured format
306
311
// This supports both text and images
307
312
const formattedMessages : any [ ] = [ ]
308
313
@@ -526,7 +531,8 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
526
531
}
527
532
528
533
/**
529
- * Prepares the structured input and conversation continuity parameters for a Responses API call.
534
+ * Prepares the input and conversation continuity parameters for a Responses API call.
535
+ * Decides whether to send full conversation or just the latest message based on previousResponseId.
530
536
*
531
537
* - If a `previousResponseId` is available (either from metadata or the handler's state),
532
538
* it formats only the most recent user message for the input and returns the response ID
@@ -535,7 +541,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
535
541
*
536
542
* @returns An object containing the formatted input and the previous response ID (if used).
537
543
*/
538
- private prepareStructuredInput (
544
+ private prepareResponsesApiInput (
539
545
systemPrompt : string ,
540
546
messages : Anthropic . Messages . MessageParam [ ] ,
541
547
metadata ?: ApiHandlerCreateMessageMetadata ,
@@ -560,7 +566,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
560
566
return { formattedInput : [ ] , previousResponseId }
561
567
} else {
562
568
// Format full conversation history (returns an array of structured messages)
563
- const formattedInput = this . formatStructuredInput ( systemPrompt , messages )
569
+ const formattedInput = this . formatFullConversation ( systemPrompt , messages )
564
570
return { formattedInput }
565
571
}
566
572
}
@@ -1108,10 +1114,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
1108
1114
return info . reasoningEffort as ReasoningEffortWithMinimal | undefined
1109
1115
}
1110
1116
1111
- private isResponsesApiModel ( modelId : string ) : boolean {
1112
- // ALL models now use the Responses API
1113
- return true
1114
- }
1117
+ // Removed isResponsesApiModel method as ALL models now use the Responses API
1115
1118
1116
1119
override getModel ( ) {
1117
1120
const modelId = this . options . apiModelId
@@ -1126,18 +1129,18 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
1126
1129
modelId : id ,
1127
1130
model : info ,
1128
1131
settings : this . options ,
1129
- defaultTemperature : id . startsWith ( "gpt-5" ) ? GPT5_DEFAULT_TEMPERATURE : OPENAI_NATIVE_DEFAULT_TEMPERATURE ,
1132
+ defaultTemperature : id . startsWith ( GPT5_MODEL_PREFIX )
1133
+ ? GPT5_DEFAULT_TEMPERATURE
1134
+ : OPENAI_NATIVE_DEFAULT_TEMPERATURE ,
1130
1135
} )
1131
1136
1132
- // For models using the Responses API (GPT-5 and Codex Mini), ensure we support reasoning effort
1133
- if ( this . isResponsesApiModel ( id ) ) {
1134
- const effort =
1135
- ( this . options . reasoningEffort as ReasoningEffortWithMinimal | undefined ) ??
1136
- ( info . reasoningEffort as ReasoningEffortWithMinimal | undefined )
1137
+ // For models using the Responses API, ensure we support reasoning effort
1138
+ const effort =
1139
+ ( this . options . reasoningEffort as ReasoningEffortWithMinimal | undefined ) ??
1140
+ ( info . reasoningEffort as ReasoningEffortWithMinimal | undefined )
1137
1141
1138
- if ( effort ) {
1139
- ; ( params . reasoning as any ) = { reasoning_effort : effort }
1140
- }
1142
+ if ( effort ) {
1143
+ ; ( params . reasoning as any ) = { reasoning_effort : effort }
1141
1144
}
1142
1145
1143
1146
// The o3 models are named like "o3-mini-[reasoning-effort]", which are
0 commit comments