@@ -87,21 +87,81 @@ describe('generateText', () => {
8787 await runtime . generateText ( input , {
8888 includeCharacter : false ,
8989 temperature : 0.9 ,
90+ topP : 0.95 ,
91+ topK : 40 ,
92+ minP : 0.05 ,
93+ seed : 42 ,
94+ repetitionPenalty : 1.1 ,
9095 maxTokens : 500 ,
96+ minTokens : 50 ,
9197 frequencyPenalty : 0.5 ,
9298 presencePenalty : 0.3 ,
9399 stopSequences : [ '\n\n' , 'END' ] ,
100+ user : 'custom-user-id' ,
101+ responseFormat : { type : 'json_object' } ,
94102 } ) ;
95103
96104 expect ( mockUseModel ) . toHaveBeenCalledTimes ( 1 ) ;
97105
98106 const callArgs = mockUseModel . mock . calls [ 0 ] ;
99107 const params = callArgs [ 1 ] ;
100108 expect ( params . temperature ) . toBe ( 0.9 ) ;
109+ expect ( params . topP ) . toBe ( 0.95 ) ;
110+ expect ( params . topK ) . toBe ( 40 ) ;
111+ expect ( params . minP ) . toBe ( 0.05 ) ;
112+ expect ( params . seed ) . toBe ( 42 ) ;
113+ expect ( params . repetitionPenalty ) . toBe ( 1.1 ) ;
101114 expect ( params . maxTokens ) . toBe ( 500 ) ;
115+ expect ( params . minTokens ) . toBe ( 50 ) ;
102116 expect ( params . frequencyPenalty ) . toBe ( 0.5 ) ;
103117 expect ( params . presencePenalty ) . toBe ( 0.3 ) ;
104118 expect ( params . stopSequences ) . toEqual ( [ '\n\n' , 'END' ] ) ;
119+ expect ( params . user ) . toBe ( 'custom-user-id' ) ;
120+ expect ( params . responseFormat ) . toEqual ( { type : 'json_object' } ) ;
121+ } ) ;
122+
123+ it ( 'should auto-populate user from character name when not provided' , async ( ) => {
124+ const input = 'Test prompt' ;
125+ await runtime . generateText ( input , {
126+ includeCharacter : false ,
127+ } ) ;
128+
129+ expect ( mockUseModel ) . toHaveBeenCalledTimes ( 1 ) ;
130+
131+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
132+ const params = callArgs [ 1 ] ;
133+ // Should auto-populate from character name
134+ expect ( params . user ) . toBe ( 'TestBot' ) ;
135+ } ) ;
136+
137+ it ( 'should preserve explicitly provided empty string for user parameter' , async ( ) => {
138+ const input = 'Test prompt' ;
139+ await runtime . generateText ( input , {
140+ includeCharacter : false ,
141+ user : '' ,
142+ } ) ;
143+
144+ expect ( mockUseModel ) . toHaveBeenCalledTimes ( 1 ) ;
145+
146+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
147+ const params = callArgs [ 1 ] ;
148+ // Should preserve empty string, not override with character name
149+ expect ( params . user ) . toBe ( '' ) ;
150+ } ) ;
151+
152+ it ( 'should preserve explicitly provided null for user parameter' , async ( ) => {
153+ const input = 'Test prompt' ;
154+ await runtime . generateText ( input , {
155+ includeCharacter : false ,
156+ user : null as any ,
157+ } ) ;
158+
159+ expect ( mockUseModel ) . toHaveBeenCalledTimes ( 1 ) ;
160+
161+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
162+ const params = callArgs [ 1 ] ;
163+ // Should preserve null, not override with character name
164+ expect ( params . user ) . toBeNull ( ) ;
105165 } ) ;
106166
107167 it ( 'should handle character with array bio' , async ( ) => {
@@ -217,4 +277,96 @@ describe('generateText', () => {
217277 expect ( params . temperature ) . toBe ( 0.3 ) ;
218278 expect ( params . prompt ) . toContain ( 'About TestBot' ) ; // Character context included
219279 } ) ;
280+
281+ it ( 'should handle responseFormat as string' , async ( ) => {
282+ const input = 'Generate JSON' ;
283+ await runtime . generateText ( input , {
284+ includeCharacter : false ,
285+ responseFormat : 'json' ,
286+ } ) ;
287+
288+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
289+ const params = callArgs [ 1 ] ;
290+ expect ( params . responseFormat ) . toBe ( 'json' ) ;
291+ } ) ;
292+
293+ it ( 'should handle empty stopSequences array' , async ( ) => {
294+ const input = 'Test prompt' ;
295+ await runtime . generateText ( input , {
296+ includeCharacter : false ,
297+ stopSequences : [ ] ,
298+ } ) ;
299+
300+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
301+ const params = callArgs [ 1 ] ;
302+ expect ( params . stopSequences ) . toEqual ( [ ] ) ;
303+ } ) ;
304+
305+ it ( 'should handle missing character name for user auto-population' , async ( ) => {
306+ const characterNoName : Character = {
307+ id : stringToUuid ( 'no-name' ) ,
308+ name : '' ,
309+ bio : 'Test bio' ,
310+ } ;
311+
312+ runtime = new AgentRuntime ( {
313+ character : characterNoName ,
314+ } ) ;
315+ mockUseModel = mock ( ) . mockResolvedValue ( 'Response' ) ;
316+ runtime . useModel = mockUseModel ;
317+
318+ await runtime . generateText ( 'Test' , {
319+ includeCharacter : false ,
320+ } ) ;
321+
322+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
323+ const params = callArgs [ 1 ] ;
324+ // Should use empty string if character name is empty
325+ expect ( params . user ) . toBe ( '' ) ;
326+ } ) ;
327+
328+ it ( 'should handle undefined character for user auto-population' , async ( ) => {
329+ runtime = new AgentRuntime ( {
330+ character : undefined as any ,
331+ } ) ;
332+ mockUseModel = mock ( ) . mockResolvedValue ( 'Response' ) ;
333+ runtime . useModel = mockUseModel ;
334+
335+ await runtime . generateText ( 'Test' , {
336+ includeCharacter : false ,
337+ } ) ;
338+
339+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
340+ const params = callArgs [ 1 ] ;
341+ // Should use undefined if character is missing
342+ expect ( params . user ) . toBeUndefined ( ) ;
343+ } ) ;
344+
345+ it ( 'should handle all parameters being undefined' , async ( ) => {
346+ const input = 'Simple prompt' ;
347+ await runtime . generateText ( input , {
348+ includeCharacter : false ,
349+ } ) ;
350+
351+ const callArgs = mockUseModel . mock . calls [ 0 ] ;
352+ const params = callArgs [ 1 ] ;
353+
354+ // Verify required params exist
355+ expect ( params . prompt ) . toBe ( 'Simple prompt' ) ;
356+ expect ( params . user ) . toBe ( 'TestBot' ) ; // Auto-populated
357+
358+ // Verify optional params are not set when not provided
359+ expect ( params . maxTokens ) . toBeUndefined ( ) ;
360+ expect ( params . minTokens ) . toBeUndefined ( ) ;
361+ expect ( params . temperature ) . toBeUndefined ( ) ;
362+ expect ( params . topP ) . toBeUndefined ( ) ;
363+ expect ( params . topK ) . toBeUndefined ( ) ;
364+ expect ( params . minP ) . toBeUndefined ( ) ;
365+ expect ( params . seed ) . toBeUndefined ( ) ;
366+ expect ( params . repetitionPenalty ) . toBeUndefined ( ) ;
367+ expect ( params . frequencyPenalty ) . toBeUndefined ( ) ;
368+ expect ( params . presencePenalty ) . toBeUndefined ( ) ;
369+ expect ( params . stopSequences ) . toBeUndefined ( ) ;
370+ expect ( params . responseFormat ) . toBeUndefined ( ) ;
371+ } ) ;
220372} ) ;
0 commit comments