@@ -66,8 +66,16 @@ vi.mock<typeof import("use-stick-to-bottom")>(
6666) ;
6767
6868// Custom format function for messagesToMarkdown test
69- const customFormatMessage = ( msg : { role : string ; content : string } ) =>
70- `[${ msg . role } ]: ${ msg . content } ` ;
69+ const customFormatMessage = ( msg : {
70+ role : string ;
71+ parts : { type : string ; text ?: string } [ ] ;
72+ } ) => {
73+ const text = msg . parts
74+ . filter ( ( p ) => p . type === "text" )
75+ . map ( ( p ) => p . text )
76+ . join ( "" ) ;
77+ return `[${ msg . role } ]: ${ text } ` ;
78+ } ;
7179
7280describe ( "conversation" , ( ) => {
7381 it ( "renders children" , ( ) => {
@@ -219,13 +227,19 @@ describe("conversationScrollButton", () => {
219227 } ) ;
220228} ) ;
221229
230+ const makeMessage = ( role : "user" | "assistant" | "system" , text : string ) => ( {
231+ id : `${ role } -${ text } ` ,
232+ parts : [ { text, type : "text" as const } ] ,
233+ role,
234+ } ) ;
235+
222236// Function name as describe title is a valid testing pattern
223237// oxlint-disable-next-line eslint-plugin-jest(valid-title)
224238describe ( messagesToMarkdown , ( ) => {
225239 it ( "converts messages to markdown format" , ( ) => {
226240 const messages = [
227- { content : "Hello ", role : "user" as const } ,
228- { content : "Hi there!" , role : "assistant" as const } ,
241+ makeMessage ( "user ", "Hello" ) ,
242+ makeMessage ( "assistant" , "Hi there!" ) ,
229243 ] ;
230244
231245 const result = messagesToMarkdown ( messages ) ;
@@ -240,8 +254,8 @@ describe(messagesToMarkdown, () => {
240254
241255 it ( "uses custom formatMessage function" , ( ) => {
242256 const messages = [
243- { content : "Hello ", role : "user" as const } ,
244- { content : "Hi ", role : "assistant" as const } ,
257+ makeMessage ( "user ", "Hello" ) ,
258+ makeMessage ( "assistant ", "Hi" ) ,
245259 ] ;
246260
247261 const result = messagesToMarkdown ( messages , customFormatMessage ) ;
@@ -251,20 +265,39 @@ describe(messagesToMarkdown, () => {
251265
252266 it ( "handles all role types" , ( ) => {
253267 const messages = [
254- { content : "User msg" , role : "user" as const } ,
255- { content : "Assistant msg" , role : "assistant" as const } ,
256- { content : "System msg" , role : "system" as const } ,
257- { content : "Tool msg" , role : "tool" as const } ,
258- { content : "Data msg" , role : "data" as const } ,
268+ makeMessage ( "user" , "User msg" ) ,
269+ makeMessage ( "assistant" , "Assistant msg" ) ,
270+ makeMessage ( "system" , "System msg" ) ,
259271 ] ;
260272
261273 const result = messagesToMarkdown ( messages ) ;
262274
263275 expect ( result ) . toContain ( "**User:** User msg" ) ;
264276 expect ( result ) . toContain ( "**Assistant:** Assistant msg" ) ;
265277 expect ( result ) . toContain ( "**System:** System msg" ) ;
266- expect ( result ) . toContain ( "**Tool:** Tool msg" ) ;
267- expect ( result ) . toContain ( "**Data:** Data msg" ) ;
278+ } ) ;
279+
280+ it ( "extracts text from multiple parts" , ( ) => {
281+ const message = {
282+ id : "multi" ,
283+ parts : [
284+ { text : "Hello " , type : "text" as const } ,
285+ {
286+ args : { } ,
287+ result : { } ,
288+ state : "result" as const ,
289+ toolInvocationId : "1" ,
290+ toolName : "test" ,
291+ type : "tool-invocation" as const ,
292+ } ,
293+ { text : "world" , type : "text" as const } ,
294+ ] ,
295+ role : "assistant" as const ,
296+ } ;
297+
298+ const result = messagesToMarkdown ( [ message ] ) ;
299+
300+ expect ( result ) . toBe ( "**Assistant:** Hello world" ) ;
268301 } ) ;
269302} ) ;
270303
@@ -310,8 +343,8 @@ const setupDomClickTracker = () => {
310343
311344describe ( "conversationDownload" , ( ) => {
312345 const mockMessages = [
313- { content : "Hello ", role : "user" as const } ,
314- { content : "Hi there!" , role : "assistant" as const } ,
346+ makeMessage ( "user ", "Hello" ) ,
347+ makeMessage ( "assistant" , "Hi there!" ) ,
315348 ] ;
316349
317350 it ( "renders download button" , ( ) => {
0 commit comments