File-Upload: Attachments-Tabelle, Base64-Speicherung, Frontend mit Drag&Drop/Paste/Preview, Error-Handling Fix
This commit is contained in:
1 parent
680f1d6fe2
commit
1271c9c651
11 files changed
+513
-11
No files matched your search
@@ -97,6 +97,21 @@ public class DatabaseService
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_chain ON messages(chain_id);
|
||||
");
|
||||
|
||||
conn.Execute(@"
|
||||
CREATE TABLE IF NOT EXISTS attachments (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
message_id INTEGER NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
media_type TEXT NOT NULL,
|
||||
file_name TEXT,
|
||||
data TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
FOREIGN KEY (message_id) REFERENCES messages(id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_attachments_message ON attachments(message_id);
|
||||
");
|
||||
|
||||
// Migrations
|
||||
TryAddColumn(conn, "sessions", "agent_id", "TEXT");
|
||||
TryAddColumn(conn, "sessions", "description", "TEXT");
|
||||
@@ -105,6 +120,7 @@ public class DatabaseService
|
||||
TryAddColumn(conn, "sessions", "context", "TEXT");
|
||||
TryAddColumn(conn, "sessions", "is_deleted", "INTEGER NOT NULL DEFAULT 0");
|
||||
TryAddColumn(conn, "chains", "agent_id", "TEXT");
|
||||
TryAddColumn(conn, "messages", "attachment_count", "INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
|
||||
private void TryAddColumn(SqliteConnection conn, string table, string column, string type)
|
||||
@@ -338,12 +354,40 @@ public class DatabaseService
|
||||
using var conn = CreateConnection();
|
||||
record.CreatedAt = DateTime.UtcNow.ToString("o");
|
||||
return await conn.ExecuteScalarAsync<long>(@"
|
||||
INSERT INTO messages (chain_id, role, type, content, tool_name, tool_call_id, is_error, iteration, created_at)
|
||||
VALUES (@ChainId, @Role, @Type, @Content, @ToolName, @ToolCallId, @IsError, @Iteration, @CreatedAt);
|
||||
INSERT INTO messages (chain_id, role, type, content, tool_name, tool_call_id, is_error, iteration, attachment_count, created_at)
|
||||
VALUES (@ChainId, @Role, @Type, @Content, @ToolName, @ToolCallId, @IsError, @Iteration, @AttachmentCount, @CreatedAt);
|
||||
SELECT last_insert_rowid();
|
||||
", record);
|
||||
}
|
||||
|
||||
// ── Attachments ──
|
||||
|
||||
public async Task SaveAttachment(AttachmentRecord attachment)
|
||||
{
|
||||
using var conn = CreateConnection();
|
||||
attachment.CreatedAt = DateTime.UtcNow.ToString("o");
|
||||
await conn.ExecuteAsync(@"
|
||||
INSERT INTO attachments (message_id, type, media_type, file_name, data, created_at)
|
||||
VALUES (@MessageId, @Type, @MediaType, @FileName, @Data, @CreatedAt)
|
||||
", attachment);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AttachmentRecord>> GetAttachments(long messageId)
|
||||
{
|
||||
using var conn = CreateConnection();
|
||||
return await conn.QueryAsync<AttachmentRecord>(
|
||||
"SELECT * FROM attachments WHERE message_id = @messageId ORDER BY id",
|
||||
new { messageId });
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AttachmentRecord>> GetAttachmentsForMessages(IEnumerable<long> messageIds)
|
||||
{
|
||||
using var conn = CreateConnection();
|
||||
return await conn.QueryAsync<AttachmentRecord>(
|
||||
"SELECT * FROM attachments WHERE message_id IN @messageIds ORDER BY id",
|
||||
new { messageIds });
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<MessageRecord>> GetChainMessages(string chainId)
|
||||
{
|
||||
using var conn = CreateConnection();
|
||||
|
||||
Reference in new issue
Block a user