mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 11:39:01 +01:00 
			
		
		
		
	fix(llm): make sure that we're referencing the correct Note ID when saving
This commit is contained in:
		
							parent
							
								
									ebb1654d0e
								
							
						
					
					
						commit
						c2eed44150
					
				| @ -182,17 +182,30 @@ export default class AiChatTypeWidget extends TypeWidget { | |||||||
| 
 | 
 | ||||||
|     // Save chat data to the note
 |     // Save chat data to the note
 | ||||||
|     async saveData(data: any) { |     async saveData(data: any) { | ||||||
|         if (!this.note) { |         // If we have a noteId in the data, that's the AI Chat note we should save to
 | ||||||
|  |         // This happens when the chat panel is saving its conversation
 | ||||||
|  |         const targetNoteId = data.noteId; | ||||||
|  |          | ||||||
|  |         // If no noteId in data, use the current note (for new chats)
 | ||||||
|  |         const noteIdToUse = targetNoteId || this.note?.noteId; | ||||||
|  |          | ||||||
|  |         if (!noteIdToUse) { | ||||||
|  |             console.warn("Cannot save AI Chat data: no note ID available"); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             console.log(`AiChatTypeWidget: Saving data for note ${this.note.noteId}`); |             console.log(`AiChatTypeWidget: Saving data for note ${noteIdToUse} (current note: ${this.note?.noteId}, data.noteId: ${data.noteId})`); | ||||||
|  | 
 | ||||||
|  |             // Safety check: if we have both IDs and they don't match, warn about it
 | ||||||
|  |             if (targetNoteId && this.note?.noteId && targetNoteId !== this.note.noteId) { | ||||||
|  |                 console.warn(`Note ID mismatch: saving to ${targetNoteId} but current note is ${this.note.noteId}`); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             // Format the data properly - this is the canonical format of the data
 |             // Format the data properly - this is the canonical format of the data
 | ||||||
|             const formattedData = { |             const formattedData = { | ||||||
|                 messages: data.messages || [], |                 messages: data.messages || [], | ||||||
|                 noteId: this.note.noteId, // Always use the note's own ID
 |                 noteId: noteIdToUse, // Always preserve the correct note ID
 | ||||||
|                 toolSteps: data.toolSteps || [], |                 toolSteps: data.toolSteps || [], | ||||||
|                 sources: data.sources || [], |                 sources: data.sources || [], | ||||||
|                 metadata: { |                 metadata: { | ||||||
| @ -201,8 +214,8 @@ export default class AiChatTypeWidget extends TypeWidget { | |||||||
|                 } |                 } | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|             // Save the data to the note
 |             // Save the data to the correct note
 | ||||||
|             await server.put(`notes/${this.note.noteId}/data`, { |             await server.put(`notes/${noteIdToUse}/data`, { | ||||||
|                 content: JSON.stringify(formattedData, null, 2) |                 content: JSON.stringify(formattedData, null, 2) | ||||||
|             }); |             }); | ||||||
|         } catch (e) { |         } catch (e) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 perf3ct
						perf3ct