@@ -3,13 +3,35 @@ export const HTTP_BASE='https://orp.aww.4ev.link/ws'
33export const buildBody = ( ) => {
44 const { USER , SUNE , state, payloadWithSampling} = window ;
55 const msgs = [ ] ;
6- if ( USER . masterPrompt && ! SUNE . ignore_master_prompt ) msgs . push ( { role :'system' , content :[ { type :'text' , text :USER . masterPrompt } ] } ) ;
7- if ( SUNE . system_prompt ) msgs . push ( { role :'system' , content :[ { type :'text' , text :SUNE . system_prompt } ] } ) ;
8- msgs . push ( ...state . messages . filter ( m => m . role !== 'system' ) . map ( m => ( {
9- role :m . role ,
10- content :m . content ,
11- ...( m . images ?{ images :m . images } :{ } )
12- } ) ) ) ;
6+
7+ const mPrompt = ( USER . masterPrompt || '' ) . trim ( ) ;
8+ if ( mPrompt && ! SUNE . ignore_master_prompt ) {
9+ msgs . push ( { role :'system' , content : mPrompt } ) ;
10+ }
11+
12+ const sPrompt = ( SUNE . system_prompt || '' ) . trim ( ) ;
13+ if ( sPrompt ) {
14+ msgs . push ( { role :'system' , content : sPrompt } ) ;
15+ }
16+
17+ state . messages . filter ( m => m . role !== 'system' ) . forEach ( m => {
18+ let content = Array . isArray ( m . content ) ? [ ...m . content ] : [ { type :'text' , text :String ( m . content || '' ) } ] ;
19+
20+ // Filter out empty text parts which cause 400 errors on strict providers like Moonshot
21+ content = content . filter ( p => p . type !== 'text' || ( p . text && p . text . trim ( ) . length > 0 ) ) ;
22+
23+ // Ensure every message has at least some text content if it's otherwise empty (e.g. multimodal only)
24+ if ( content . length === 0 || ! content . some ( p => p . type === 'text' ) ) {
25+ content . push ( { type : 'text' , text : '.' } ) ;
26+ }
27+
28+ msgs . push ( {
29+ role : m . role ,
30+ content : content ,
31+ ...( m . images ?. length ? { images : m . images } : { } )
32+ } ) ;
33+ } ) ;
34+
1335 const b = payloadWithSampling ( { model :SUNE . model . replace ( / ^ ( o r : | o a i : | g : | c l a : | c f : ) / , '' ) , messages :msgs , stream :true } ) ;
1436 if ( SUNE . json_output ) { let s ; try { s = JSON . parse ( SUNE . json_schema || 'null' ) } catch { s = null } if ( s && typeof s === 'object' && Object . keys ( s ) . length > 0 ) { b . response_format = { type :'json_schema' , json_schema :s } } else { b . response_format = { type :'json_object' } } }
1537 b . reasoning = { ...( SUNE . reasoning_effort && SUNE . reasoning_effort !== 'default' ?{ effort :SUNE . reasoning_effort } :{ } ) , exclude :! SUNE . include_thoughts } ;
0 commit comments