@@ -3,6 +3,8 @@ import { BACKEND_URL } from '@codebuff/sdk'
33import { useChatStore } from '../state/chat-store'
44import { getAuthToken } from '../utils/auth'
55import { logger } from '../utils/logger'
6+ import { getSystemMessage } from '../utils/message-history'
7+
68import type { PostUserMessageFn } from '../types/contracts/send-message'
79
810interface UsageResponse {
@@ -22,12 +24,7 @@ export async function handleUsageCommand(): Promise<{
2224 if ( ! authToken ) {
2325 const postUserMessage : PostUserMessageFn = ( prev ) => [
2426 ...prev ,
25- {
26- id : `sys-${ Date . now ( ) } ` ,
27- variant : 'ai' as const ,
28- content : 'Please log in first to view your usage.' ,
29- timestamp : new Date ( ) . toISOString ( ) ,
30- } ,
27+ getSystemMessage ( 'Please log in first to view your usage.' ) ,
3128 ]
3229 return { postUserMessage }
3330 }
@@ -53,12 +50,7 @@ export async function handleUsageCommand(): Promise<{
5350
5451 const postUserMessage : PostUserMessageFn = ( prev ) => [
5552 ...prev ,
56- {
57- id : `sys-${ Date . now ( ) } ` ,
58- variant : 'ai' as const ,
59- content : `Failed to fetch usage data: ${ errorText } ` ,
60- timestamp : new Date ( ) . toISOString ( ) ,
61- } ,
53+ getSystemMessage ( `Failed to fetch usage data: ${ errorText } ` ) ,
6254 ]
6355 return { postUserMessage }
6456 }
@@ -96,12 +88,7 @@ export async function handleUsageCommand(): Promise<{
9688
9789 const postUserMessage : PostUserMessageFn = ( prev ) => [
9890 ...prev ,
99- {
100- id : `sys-${ Date . now ( ) } ` ,
101- variant : 'ai' as const ,
102- content : usageMessage ,
103- timestamp : new Date ( ) . toISOString ( ) ,
104- } ,
91+ getSystemMessage ( usageMessage ) ,
10592 ]
10693 return { postUserMessage }
10794 } catch ( error ) {
@@ -115,12 +102,7 @@ export async function handleUsageCommand(): Promise<{
115102
116103 const postUserMessage : PostUserMessageFn = ( prev ) => [
117104 ...prev ,
118- {
119- id : `sys-${ Date . now ( ) } ` ,
120- variant : 'ai' as const ,
121- content : 'Error checking usage. Please try again later.' ,
122- timestamp : new Date ( ) . toISOString ( ) ,
123- } ,
105+ getSystemMessage ( 'Error checking usage. Please try again later.' ) ,
124106 ]
125107 return { postUserMessage }
126108 }
0 commit comments