1- import { type AssistantMessage , type Message , type Part } from "@opencode-ai/sdk/v2"
2-
31type Session = {
42 id : string
53 title : string
@@ -9,18 +7,43 @@ type Session = {
97 }
108}
119
10+ type Message = {
11+ role : "user" | "assistant"
12+ agent ?: string
13+ modelID ?: string
14+ time : {
15+ created ?: number
16+ completed ?: number
17+ }
18+ }
19+
20+ type Part = {
21+ type : string
22+ synthetic ?: boolean
23+ text ?: string
24+ tool ?: string
25+ state ?: {
26+ input ?: unknown
27+ output ?: string
28+ error ?: string
29+ status : "pending" | "running" | "completed" | "error"
30+ }
31+ }
32+
1233const titlecase = ( value : string ) => ( value ? value . charAt ( 0 ) . toUpperCase ( ) + value . slice ( 1 ) : value )
1334
14- const formatAssistant = ( msg : AssistantMessage ) => {
35+ const formatAssistant = ( msg : Message ) => {
1536 const duration =
1637 msg . time . completed && msg . time . created ? ( ( msg . time . completed - msg . time . created ) / 1000 ) . toFixed ( 1 ) + "s" : ""
17- return `## Assistant (${ titlecase ( msg . agent ) } · ${ msg . modelID } ${ duration ? ` · ${ duration } ` : "" } )\n\n`
38+ const agent = msg . agent ? titlecase ( msg . agent ) : "Assistant"
39+ const model = msg . modelID ?? ""
40+ return `## Assistant (${ agent } ${ model ? ` · ${ model } ` : "" } ${ duration ? ` · ${ duration } ` : "" } )\n\n`
1841}
1942
2043const formatPart = ( part : Part ) => {
21- if ( part . type === "text" && ! part . synthetic ) return `${ part . text } \n\n`
22- if ( part . type === "reasoning" ) return `_Thinking:_\n\n${ part . text } \n\n`
23- if ( part . type !== "tool" ) return ""
44+ if ( part . type === "text" && part . text && ! part . synthetic ) return `${ part . text } \n\n`
45+ if ( part . type === "reasoning" && part . text ) return `_Thinking:_\n\n${ part . text } \n\n`
46+ if ( part . type !== "tool" || ! part . tool || ! part . state ) return ""
2447
2548 const input = part . state . input
2649 ? `\n**Input:**\n\`\`\`json\n${ JSON . stringify ( part . state . input , null , 2 ) } \n\`\`\`\n`
0 commit comments