fix the table reference

This commit is contained in:
perf3ct 2025-04-15 22:37:57 +00:00
parent e5aab5bc04
commit 0bca44f8e0
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232

View File

@ -130,9 +130,9 @@ export class ChatStorageService {
*/ */
async getAllChats(): Promise<StoredChat[]> { async getAllChats(): Promise<StoredChat[]> {
const chats = await sql.getRows<{noteId: string, title: string, dateCreated: string, dateModified: string, content: string}>( const chats = await sql.getRows<{noteId: string, title: string, dateCreated: string, dateModified: string, content: string}>(
`SELECT notes.noteId, notes.title, notes.dateCreated, notes.dateModified, note_contents.content `SELECT notes.noteId, notes.title, notes.dateCreated, notes.dateModified, blobs.content
FROM notes FROM notes
JOIN note_contents ON notes.noteId = note_contents.noteId JOIN blobs ON notes.blobId = blobs.blobId
JOIN attributes ON notes.noteId = attributes.noteId JOIN attributes ON notes.noteId = attributes.noteId
WHERE attributes.name = ? AND attributes.value = ? WHERE attributes.name = ? AND attributes.value = ?
ORDER BY notes.dateModified DESC`, ORDER BY notes.dateModified DESC`,
@ -144,12 +144,12 @@ export class ChatStorageService {
let metadata: ChatMetadata = {}; let metadata: ChatMetadata = {};
let createdAt = new Date(chat.dateCreated); let createdAt = new Date(chat.dateCreated);
let updatedAt = new Date(chat.dateModified); let updatedAt = new Date(chat.dateModified);
try { try {
const content = JSON.parse(chat.content); const content = JSON.parse(chat.content);
messages = content.messages || []; messages = content.messages || [];
metadata = content.metadata || {}; metadata = content.metadata || {};
// Use stored dates if available // Use stored dates if available
if (content.createdAt) { if (content.createdAt) {
createdAt = new Date(content.createdAt); createdAt = new Date(content.createdAt);
@ -178,9 +178,9 @@ export class ChatStorageService {
*/ */
async getChat(chatId: string): Promise<StoredChat | null> { async getChat(chatId: string): Promise<StoredChat | null> {
const chat = await sql.getRow<{noteId: string, title: string, dateCreated: string, dateModified: string, content: string}>( const chat = await sql.getRow<{noteId: string, title: string, dateCreated: string, dateModified: string, content: string}>(
`SELECT notes.noteId, notes.title, notes.dateCreated, notes.dateModified, note_contents.content `SELECT notes.noteId, notes.title, notes.dateCreated, notes.dateModified, blobs.content
FROM notes FROM notes
JOIN note_contents ON notes.noteId = note_contents.noteId JOIN blobs ON notes.blobId = blobs.blobId
WHERE notes.noteId = ?`, WHERE notes.noteId = ?`,
[chatId] [chatId]
); );
@ -193,12 +193,12 @@ export class ChatStorageService {
let metadata: ChatMetadata = {}; let metadata: ChatMetadata = {};
let createdAt = new Date(chat.dateCreated); let createdAt = new Date(chat.dateCreated);
let updatedAt = new Date(chat.dateModified); let updatedAt = new Date(chat.dateModified);
try { try {
const content = JSON.parse(chat.content); const content = JSON.parse(chat.content);
messages = content.messages || []; messages = content.messages || [];
metadata = content.metadata || {}; metadata = content.metadata || {};
// Use stored dates if available // Use stored dates if available
if (content.createdAt) { if (content.createdAt) {
createdAt = new Date(content.createdAt); createdAt = new Date(content.createdAt);
@ -225,9 +225,9 @@ export class ChatStorageService {
* Update messages in a chat * Update messages in a chat
*/ */
async updateChat( async updateChat(
chatId: string, chatId: string,
messages: Message[], messages: Message[],
title?: string, title?: string,
metadata?: ChatMetadata metadata?: ChatMetadata
): Promise<StoredChat | null> { ): Promise<StoredChat | null> {
const chat = await this.getChat(chatId); const chat = await this.getChat(chatId);
@ -247,7 +247,7 @@ export class ChatStorageService {
// Update content directly using SQL since we don't have a method for this in the notes service // Update content directly using SQL since we don't have a method for this in the notes service
await sql.execute( await sql.execute(
`UPDATE note_contents SET content = ? WHERE noteId = ?`, `UPDATE blobs SET content = ? WHERE blobId = (SELECT blobId FROM notes WHERE noteId = ?)`,
[JSON.stringify({ [JSON.stringify({
messages, messages,
metadata: updatedMetadata, metadata: updatedMetadata,
@ -296,7 +296,7 @@ export class ChatStorageService {
*/ */
async recordToolExecution( async recordToolExecution(
chatId: string, chatId: string,
toolName: string, toolName: string,
toolId: string, toolId: string,
args: Record<string, any> | string, args: Record<string, any> | string,
result: string | Record<string, any>, result: string | Record<string, any>,
@ -341,7 +341,7 @@ export class ChatStorageService {
* This helps maintain a record of all tool calls even if messages are truncated * This helps maintain a record of all tool calls even if messages are truncated
*/ */
private extractToolExecutionsFromMessages( private extractToolExecutionsFromMessages(
messages: Message[], messages: Message[],
existingToolExecutions: ToolExecution[] = [] existingToolExecutions: ToolExecution[] = []
): ToolExecution[] { ): ToolExecution[] {
const toolExecutions = [...existingToolExecutions]; const toolExecutions = [...existingToolExecutions];