@@ -10,8 +10,8 @@ export class AIService {
1010 this . language = language ;
1111 }
1212
13- private getApiType ( ) : 'openai' | 'claude' | 'gemini' {
14- return this . config . apiType || 'openai' ;
13+ private getApiType ( ) : 'openai' | 'openai-responses' | ' claude' | 'gemini' {
14+ return ( this . config . apiType as 'openai' | 'openai-responses' | 'claude' | 'gemini' ) || 'openai' ;
1515 }
1616
1717 private buildApiUrl ( pathWithVersion : string ) : string {
@@ -50,25 +50,33 @@ export class AIService {
5050 } ) : Promise < string > {
5151 const apiType = this . getApiType ( ) ;
5252
53- if ( apiType === 'openai' ) {
53+ if ( apiType === 'openai' || apiType === 'openai-responses' ) {
5454 const messages = [
5555 ...( options . system . trim ( )
5656 ? [ { role : 'system' , content : options . system } ]
5757 : [ ] ) ,
5858 { role : 'user' , content : options . user } ,
5959 ] ;
60- const requestBody = {
61- model : this . config . model ,
62- messages,
63- temperature : options . temperature ,
64- max_tokens : options . maxTokens ,
65- } ;
60+
61+ const requestBody = apiType === 'openai-responses'
62+ ? {
63+ model : this . config . model ,
64+ input : messages ,
65+ temperature : options . temperature ,
66+ max_output_tokens : options . maxTokens ,
67+ }
68+ : {
69+ model : this . config . model ,
70+ messages,
71+ temperature : options . temperature ,
72+ max_tokens : options . maxTokens ,
73+ } ;
6674
6775 let data : any ;
6876 if ( backend . isAvailable && this . config . id ) {
6977 data = await backend . proxyAIRequest ( this . config . id , requestBody ) ;
7078 } else {
71- const url = this . buildApiUrl ( 'v1/chat/completions' ) ;
79+ const url = this . buildApiUrl ( apiType === 'openai-responses' ? 'v1/responses' : 'v1/chat/completions' ) ;
7280 const response = await fetch ( url , {
7381 method : 'POST' ,
7482 headers : {
@@ -85,11 +93,24 @@ export class AIService {
8593 data = await response . json ( ) ;
8694 }
8795
88- const content = data . choices ?. [ 0 ] ?. message ?. content ;
89- if ( ! content ) {
90- throw new Error ( 'No content received from AI service' ) ;
96+ if ( apiType === 'openai-responses' ) {
97+ const outputText = typeof data ?. output_text === 'string' ? data . output_text : '' ;
98+ if ( outputText ) return outputText ;
99+
100+ const output = data ?. output ;
101+ if ( Array . isArray ( output ) ) {
102+ const text = output
103+ . flatMap ( ( item : any ) => Array . isArray ( item ?. content ) ? item . content : [ ] )
104+ . map ( ( part : any ) => ( typeof part ?. text === 'string' ? part . text : '' ) )
105+ . join ( '' ) ;
106+ if ( text ) return text ;
107+ }
108+ } else {
109+ const content = data ?. choices ?. [ 0 ] ?. message ?. content ;
110+ if ( content ) return content ;
91111 }
92- return content ;
112+
113+ throw new Error ( 'No content received from AI service' ) ;
93114 }
94115
95116 if ( apiType === 'claude' ) {
0 commit comments