File tree Expand file tree Collapse file tree 4 files changed +10
-20
lines changed
app/project/[id]/_components/right-panel/chat-tab/chat-messages
components/store/editor/chat
packages/models/src/chat/message Expand file tree Collapse file tree 4 files changed +10
-20
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export const UserMessage = ({ message }: UserMessageProps) => {
3535 const [ isRestoring , setIsRestoring ] = useState ( false ) ;
3636
3737 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
38- const commitOid = message . content . metadata ? .snapshots ? .find ( ( s ) => s . type === MessageSnapshotType . GIT ) ?. oid ;
38+ const commitOid = message . content . metadata . snapshots . find ( ( s ) => s . type === MessageSnapshotType . GIT ) ?. oid ;
3939
4040 useEffect ( ( ) => {
4141 if ( isEditing && textareaRef . current ) {
@@ -210,7 +210,7 @@ export const UserMessage = ({ message }: UserMessageProps) => {
210210 < div className = "h-6 relative" >
211211 < div className = "absolute top-1 left-0 right-0 flex flex-row justify-start items-center w-full overflow-auto pr-16" >
212212 < div className = "flex flex-row gap-3 text-micro text-foreground-secondary" >
213- { message . content . metadata ? .context ? .map ( ( context ) => (
213+ { message . content . metadata . context . map ( ( context ) => (
214214 < SentContextPill key = { nanoid ( ) } context = { context } />
215215 ) ) }
216216 </ div >
Original file line number Diff line number Diff line change @@ -153,16 +153,13 @@ export class ConversationManager {
153153 }
154154 const userMessage = message as UserChatMessage ;
155155 const newSnapshots = [
156- ...userMessage . content . metadata ? .snapshots ?? [ ] ,
156+ ...userMessage . content . metadata . snapshots ,
157157 {
158158 type : MessageSnapshotType . GIT ,
159159 oid : commit . oid ,
160160 createdAt : new Date ( ) ,
161161 } ,
162162 ] ;
163- if ( ! userMessage . content . metadata ) {
164- userMessage . content . metadata = { } ;
165- }
166163 userMessage . content . metadata . snapshots = newSnapshots ;
167164 await api . chat . message . updateSnapshot . mutate ( {
168165 messageId : message . id ,
@@ -176,7 +173,7 @@ export class ConversationManager {
176173 console . error ( 'No conversation found' ) ;
177174 return ;
178175 }
179- const index = this . current . messages . findIndex ( ( m ) => m . id === message . id || ( m . content . metadata ? .vercelId && m . content . metadata . vercelId === message . content . metadata ? .vercelId ) ) ;
176+ const index = this . current . messages . findIndex ( ( m ) => m . id === message . id || ( m . content . metadata . vercelId && m . content . metadata . vercelId === message . content . metadata . vercelId ) ) ;
180177 if ( index === - 1 ) {
181178 this . current . messages . push ( message ) ;
182179 } else {
Original file line number Diff line number Diff line change @@ -77,12 +77,8 @@ export class ChatManager {
7777 const messagesToRemove = this . conversation . current ?. messages . filter ( ( m ) => m . createdAt >= oldMessage . createdAt ) ;
7878
7979 // Create a new message with the new content
80- const newContext = await this . context . getRefreshedContext ( oldMessage . content . metadata ?. context ?? [ ] ) ;
81- if ( ! oldMessage . content . metadata ) {
82- oldMessage . content . metadata = { } ;
83- }
80+ const newContext = await this . context . getRefreshedContext ( oldMessage . content . metadata . context ) ;
8481 oldMessage . content . metadata . context = newContext ;
85- await this . conversation . addOrReplaceMessage ( oldMessage ) ;
8682 const newMessage = await this . conversation . addUserMessage ( newMessageContent , newContext ) ;
8783 if ( ! newMessage ) {
8884 console . error ( 'Failed to add user message' ) ;
Original file line number Diff line number Diff line change @@ -9,15 +9,12 @@ export enum ChatMessageRole {
99 ASSISTANT = 'assistant' ,
1010}
1111export interface ChatMessageContent extends MastraMessageContentV2 {
12- metadata :
13- | {
14- vercelId ?: string ;
15- context ?: ChatMessageContext [ ] ;
16- snapshots ?: MessageSnapshot [ ] ;
17- }
18- | undefined ;
12+ metadata : {
13+ vercelId ?: string ;
14+ context : ChatMessageContext [ ] ;
15+ snapshots : MessageSnapshot [ ] ;
16+ } ;
1917}
20-
2118interface BaseChatMessage extends MastraMessageV2 {
2219 role : ChatMessageRole ;
2320 threadId : string ;
You can’t perform that action at this time.
0 commit comments