@@ -5,6 +5,7 @@ import type { UserMessage } from "@opencode-ai/sdk/v2"
55
66const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345"
77const SYNTHETIC_PART_ID = "prt_01234567890123456789012345"
8+ const SYNTHETIC_CALL_ID = "call_01234567890123456789012345"
89
910export const createSyntheticUserMessage = (
1011 baseMessage : WithParts ,
@@ -37,6 +38,53 @@ export const createSyntheticUserMessage = (
3738 }
3839}
3940
41+ export const createSyntheticAssistantMessageWithToolPart = (
42+ baseMessage : WithParts ,
43+ content : string ,
44+ variant ?: string ,
45+ ) : WithParts => {
46+ const userInfo = baseMessage . info as UserMessage
47+ const now = Date . now ( )
48+ return {
49+ info : {
50+ id : SYNTHETIC_MESSAGE_ID ,
51+ sessionID : userInfo . sessionID ,
52+ role : "assistant" ,
53+ agent : userInfo . agent || "code" ,
54+ parentID : userInfo . id ,
55+ modelID : userInfo . model . modelID ,
56+ providerID : userInfo . model . providerID ,
57+ mode : "default" ,
58+ path : {
59+ cwd : "/" ,
60+ root : "/" ,
61+ } ,
62+ time : { created : now , completed : now } ,
63+ cost : 0 ,
64+ tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
65+ ...( variant !== undefined && { variant } ) ,
66+ } ,
67+ parts : [
68+ {
69+ id : SYNTHETIC_PART_ID ,
70+ sessionID : userInfo . sessionID ,
71+ messageID : SYNTHETIC_MESSAGE_ID ,
72+ type : "tool" ,
73+ callID : SYNTHETIC_CALL_ID ,
74+ tool : "context_info" ,
75+ state : {
76+ status : "completed" ,
77+ input : { } ,
78+ output : content ,
79+ title : "Context Info" ,
80+ metadata : { } ,
81+ time : { start : now , end : now } ,
82+ } ,
83+ } ,
84+ ] ,
85+ }
86+ }
87+
4088/**
4189 * Extracts a human-readable key from tool metadata for display purposes.
4290 */
0 commit comments