@@ -58,39 +58,20 @@ function buildUserMessageContent(
5858 params : Record < string , any > | undefined ,
5959 content ?: Array < TextPart | ImagePart > ,
6060) : string | Array < TextPart | ImagePart > {
61+ // If we have content, return it as-is (client should have already combined prompt + content)
62+ if ( content && content . length > 0 ) {
63+ if ( content . length === 1 && content [ 0 ] . type === 'text' ) {
64+ return asUserMessage ( content [ 0 ] . text )
65+ }
66+ return content
67+ }
68+
69+ // Only prompt/params, combine and return as simple text
6170 const textParts = buildArray ( [
6271 prompt ,
6372 params && JSON . stringify ( params , null , 2 ) ,
6473 ] )
65- const combinedText = textParts . join ( '\n\n' )
66-
67- if ( ! content || content . length === 0 ) {
68- // Only prompt/params, return as simple text
69- return asUserMessage ( combinedText )
70- }
71-
72- // If we have both content and prompt/params, combine them
73- const allParts = [ ...content ]
74-
75- // Find the first text part and prepend our combined text, or add it as a new text part
76- const firstTextPartIndex = allParts . findIndex ( ( part ) => part . type === 'text' )
77- if ( firstTextPartIndex !== - 1 ) {
78- // Prepend to existing text part
79- const textPart = allParts [ firstTextPartIndex ]
80- if ( textPart . type === 'text' ) {
81- allParts [ firstTextPartIndex ] = {
82- type : 'text' as const ,
83- text : buildArray ( [ combinedText , textPart . text ] ) . join ( '\n\n' ) ,
84- }
85- }
86- } else {
87- // Add as new text part at the beginning
88- allParts . unshift ( { type : 'text' as const , text : combinedText } )
89- }
90-
91- return allParts . length === 1 && allParts [ 0 ] . type === 'text'
92- ? asUserMessage ( allParts [ 0 ] . text )
93- : allParts
74+ return asUserMessage ( textParts . join ( '\n\n' ) )
9475}
9576
9677export interface AgentOptions {
0 commit comments