@@ -87,17 +87,17 @@ export class SqliteDatabaseAdapter
87
87
async getConversationMessages ( conversationId : UUID ) : Promise < Memory [ ] > {
88
88
const conversation = await this . getConversation ( conversationId ) ;
89
89
if ( ! conversation ) return [ ] ;
90
-
90
+
91
91
const messageIds = JSON . parse ( conversation . messageIds ) ;
92
92
const messages = await Promise . all (
93
93
messageIds . map ( id => this . getMemoryById ( id ) )
94
94
) ;
95
-
95
+
96
96
return messages
97
97
. filter ( ( m ) : m is Memory => m !== null )
98
98
. map ( memory => {
99
99
let timestamp : number ;
100
-
100
+
101
101
if ( typeof memory . createdAt === 'number' ) {
102
102
timestamp = memory . createdAt ;
103
103
} else if ( typeof memory . createdAt === 'string' ) {
@@ -121,12 +121,12 @@ export class SqliteDatabaseAdapter
121
121
if ( ! conversation ) return "" ;
122
122
123
123
const messages = await this . getConversationMessages ( conversationId ) ;
124
-
124
+
125
125
// Format each message showing only username
126
126
const formattedMessages = await Promise . all ( messages . map ( async msg => {
127
127
// First try to get username from message content
128
128
let username = msg . content . username ;
129
-
129
+
130
130
// If no username in content, try to get it from accounts table
131
131
if ( ! username ) {
132
132
const account = await this . getAccountById ( msg . userId ) ;
@@ -809,7 +809,7 @@ export class SqliteDatabaseAdapter
809
809
try {
810
810
let sql ;
811
811
let params ;
812
-
812
+
813
813
// Check if we're dealing with a username or userId
814
814
if ( userIdOrUsername . includes ( '-' ) ) {
815
815
// It's a UUID
@@ -820,7 +820,7 @@ export class SqliteDatabaseAdapter
820
820
sql = "UPDATE accounts SET userRapport = userRapport + ? WHERE username = ?" ;
821
821
params = [ score , userIdOrUsername . replace ( '@' , '' ) ] ;
822
822
}
823
-
823
+
824
824
console . log ( "Setting rapport for" , userIdOrUsername , "score:" , score ) ;
825
825
this . db . prepare ( sql ) . run ( ...params ) ;
826
826
} catch ( error ) {
@@ -868,9 +868,9 @@ export class SqliteDatabaseAdapter
868
868
async getConversation ( conversationId : UUID ) : Promise < Conversation | null > {
869
869
const sql = "SELECT * FROM conversations WHERE id = ?" ;
870
870
const conversation = this . db . prepare ( sql ) . get ( conversationId ) as ( Omit < Conversation , 'status' > & { status ?: string } ) | undefined ;
871
-
871
+
872
872
if ( ! conversation ) return null ;
873
-
873
+
874
874
return {
875
875
...conversation ,
876
876
startedAt : new Date ( conversation . startedAt ) ,
@@ -882,12 +882,12 @@ export class SqliteDatabaseAdapter
882
882
async storeConversation ( conversation : Conversation ) : Promise < void > {
883
883
const sql = `
884
884
INSERT INTO conversations (
885
- id, rootTweetId, messageIds, participantIds,
885
+ id, rootTweetId, messageIds, participantIds,
886
886
startedAt, lastMessageAt, context, agentId, status
887
- )
887
+ )
888
888
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
889
889
` ;
890
-
890
+
891
891
this . db . prepare ( sql ) . run (
892
892
conversation . id ,
893
893
conversation . rootTweetId || '' , // Ensure string
@@ -912,7 +912,7 @@ export class SqliteDatabaseAdapter
912
912
const allNewIds = JSON . parse ( conversation . messageIds ) ;
913
913
const lastNewId = allNewIds [ allNewIds . length - 1 ] ; // Get the last message ID
914
914
console . log ( "added new message " , lastNewId ) ;
915
-
915
+
916
916
if ( existingIds . includes ( lastNewId ) ) {
917
917
console . log ( "message already exists" ) ;
918
918
return ; // Exit early if message already exists
@@ -949,14 +949,14 @@ export class SqliteDatabaseAdapter
949
949
async getConversationsByStatus ( status : 'ACTIVE' | 'CLOSED' , limit ?: number ) : Promise < Conversation [ ] > {
950
950
let sql = "SELECT * FROM conversations WHERE status = ?" ;
951
951
const params : any [ ] = [ status ] ;
952
-
952
+
953
953
if ( typeof limit === 'number' ) {
954
954
sql += " LIMIT ?" ;
955
955
params . push ( limit ) ;
956
956
}
957
-
957
+
958
958
const conversations = this . db . prepare ( sql ) . all ( ...params ) as ( Omit < Conversation , 'status' > & { status ?: string } ) [ ] ;
959
-
959
+
960
960
return conversations . map ( conversation => ( {
961
961
...conversation ,
962
962
startedAt : new Date ( conversation . startedAt ) ,
0 commit comments