11import { describe , expect , test } from "bun:test"
2- import type {
3- AssistantMessage ,
4- Message ,
5- Part ,
6- SessionStatus ,
7- UserMessage ,
8- } from "@opencode-ai/sdk/v2"
2+ import type { AssistantMessage , Message , Part , SessionStatus , UserMessage } from "@opencode-ai/sdk/v2"
93import {
104 ASSISTANT_SEGMENT_PARTS ,
115 createRowStabilizer ,
126 isCompactionMarker ,
137 nearestUserTurnID ,
148 projectTranscript ,
159 rowKey ,
16- type ChatTurn ,
17- type TranscriptPartition ,
1810 type TranscriptRow ,
1911} from "./chat-transcript"
2012
@@ -56,18 +48,6 @@ function reasoningPart(id: string, messageID: string, text: string): Part {
5648 return { id, sessionID : "ses_1" , messageID, type : "reasoning" , text, time : { start : 0 , end : 1 } }
5749}
5850
59- function toolPart ( id : string , messageID : string , tool : string , callID : string ) : Part {
60- return {
61- id,
62- sessionID : "ses_1" ,
63- messageID,
64- type : "tool" ,
65- callID,
66- tool,
67- state : { status : "completed" , input : { } , output : "" , title : tool , metadata : { } , time : { start : 0 , end : 1 } } ,
68- }
69- }
70-
7151function stepStartPart ( id : string , messageID : string ) : Part {
7252 return { id, sessionID : "ses_1" , messageID, type : "step-start" }
7353}
@@ -107,8 +87,12 @@ describe("projectTranscript", () => {
10787 showReasoningSummaries : true ,
10888 } )
10989
110- expect ( defaultOff . rows . flatMap ( ( row ) => ( row . type === "assistant" ? row . parts : [ ] ) ) . map ( ( part ) => part . id ) ) . toEqual ( [ "r1" , "p1" ] )
111- expect ( defaultOn . rows . flatMap ( ( row ) => ( row . type === "assistant" ? row . parts : [ ] ) ) . map ( ( part ) => part . id ) ) . toEqual ( [ "r1" , "p1" ] )
90+ expect (
91+ defaultOff . rows . flatMap ( ( row ) => ( row . type === "assistant" ? row . parts : [ ] ) ) . map ( ( part ) => part . id ) ,
92+ ) . toEqual ( [ "r1" , "p1" ] )
93+ expect ( defaultOn . rows . flatMap ( ( row ) => ( row . type === "assistant" ? row . parts : [ ] ) ) . map ( ( part ) => part . id ) ) . toEqual (
94+ [ "r1" , "p1" ] ,
95+ )
11296 } )
11397
11498 test ( "groups assistant messages by parentID into stable turns" , ( ) => {
@@ -181,11 +165,7 @@ describe("projectTranscript", () => {
181165 test ( "hides non-renderable parts from assistant segments" , ( ) => {
182166 const u1 = userMessage ( "u1" )
183167 const a1 = assistantMessage ( "a1" , "u1" )
184- const parts : Part [ ] = [
185- stepStartPart ( "s1" , "a1" ) ,
186- textPart ( "p1" , "a1" , "visible" ) ,
187- stepStartPart ( "s2" , "a1" ) ,
188- ]
168+ const parts : Part [ ] = [ stepStartPart ( "s1" , "a1" ) , textPart ( "p1" , "a1" , "visible" ) , stepStartPart ( "s2" , "a1" ) ]
189169
190170 const { rows } = projectTranscript ( { messages : [ u1 , a1 ] , getParts : partsByID ( parts ) , status : idle } )
191171
@@ -198,11 +178,7 @@ describe("projectTranscript", () => {
198178 const u1 = userMessage ( "u1" )
199179 const a1 = assistantMessage ( "a1" , "u1" )
200180 const a2 = assistantMessage ( "a2" , "u1" )
201- const parts = [
202- textPart ( "p1" , "u1" , "hello" ) ,
203- textPart ( "p2" , "a1" , "中间回复" ) ,
204- textPart ( "p3" , "a2" , "最终回复" ) ,
205- ]
181+ const parts = [ textPart ( "p1" , "u1" , "hello" ) , textPart ( "p2" , "a1" , "中间回复" ) , textPart ( "p3" , "a2" , "最终回复" ) ]
206182
207183 const { rows } = projectTranscript ( { messages : [ u1 , a1 , a2 ] , getParts : partsByID ( parts ) , status : idle } )
208184
@@ -222,9 +198,7 @@ describe("projectTranscript", () => {
222198
223199 const { rows } = projectTranscript ( { messages : [ u1 , a1 ] , getParts : partsByID ( parts ) , status : idle } )
224200
225- const assistantRows = rows . filter (
226- ( r ) : r is Extract < TranscriptRow , { type : "assistant" } > => r . type === "assistant" ,
227- )
201+ const assistantRows = rows . filter ( ( r ) : r is Extract < TranscriptRow , { type : "assistant" } > => r . type === "assistant" )
228202 expect ( assistantRows ) . toHaveLength ( 2 )
229203 expect ( assistantRows [ 0 ] ?. metaPartID ) . toBeUndefined ( )
230204 expect ( assistantRows [ 1 ] ?. metaPartID ) . toBe ( `p${ ASSISTANT_SEGMENT_PARTS + 4 } ` )
@@ -250,9 +224,9 @@ describe("projectTranscript", () => {
250224 } )
251225
252226 const findAssistant = ( rows : TranscriptRow [ ] , messageID : string ) =>
253- rows . filter ( ( r ) : r is Extract < TranscriptRow , { type : "assistant" } > => r . type === "assistant" ) . find (
254- ( r ) => r . message . id === messageID ,
255- )
227+ rows
228+ . filter ( ( r ) : r is Extract < TranscriptRow , { type : "assistant" } > => r . type === "assistant" )
229+ . find ( ( r ) => r . message . id === messageID )
256230 const firstRow = findAssistant ( first . rows , "a1" )
257231 const secondRow = findAssistant ( second . rows , "a1" )
258232 expect ( firstRow ) . toBeDefined ( )
@@ -492,7 +466,14 @@ describe("compaction marker projection", () => {
492466
493467 test ( "isCompactionMarker is false for a user message with file or agent parts" , ( ) => {
494468 const u1 = userMessage ( "u1" )
495- const filePart : Part = { id : "f1" , sessionID : "ses_1" , messageID : "u1" , type : "file" , mime : "text/plain" , url : "file:///x" }
469+ const filePart : Part = {
470+ id : "f1" ,
471+ sessionID : "ses_1" ,
472+ messageID : "u1" ,
473+ type : "file" ,
474+ mime : "text/plain" ,
475+ url : "file:///x" ,
476+ }
496477 expect ( isCompactionMarker ( u1 , partsByID ( [ compactionPart ( "cp1" , "u1" ) , filePart ] ) ) ) . toBe ( false )
497478 } )
498479
0 commit comments