@@ -10,11 +10,13 @@ import {
10
10
modifyIssueAction ,
11
11
addCommentToIssueAction ,
12
12
ideationAction ,
13
+ addCommentToPRAction ,
13
14
incorporateRepositoryState ,
14
15
getRepositoryRoomId
15
16
} from "@elizaos/plugin-github" ;
16
17
import { isOODAContent , OODAContent , OODASchema } from "./types" ;
17
18
import { oodaTemplate } from "./templates" ;
19
+ import { saveIssuesToMemory , savePullRequestsToMemory } from "./utils" ;
18
20
19
21
export class GitHubClient extends EventEmitter {
20
22
apiToken : string ;
@@ -37,7 +39,7 @@ export class GitHubClient extends EventEmitter {
37
39
this . runtime . registerAction ( modifyIssueAction ) ;
38
40
this . runtime . registerAction ( addCommentToIssueAction ) ;
39
41
this . runtime . registerAction ( ideationAction ) ;
40
-
42
+ this . runtime . registerAction ( addCommentToPRAction ) ;
41
43
elizaLogger . log ( "GitHubClient actions and providers registered." ) ;
42
44
43
45
// Start the OODA loop after initialization
@@ -86,84 +88,15 @@ export class GitHubClient extends EventEmitter {
86
88
) ;
87
89
// elizaLogger.log("Retrieved memories:", memories);
88
90
if ( fileMemories . length === 0 ) {
89
- elizaLogger . log ( "No memories found, skipping OODA cycle." ) ;
90
- // time to initialize repository and create memories
91
- const timestamp = Date . now ( ) ;
92
- const userIdUUID = stringToUuid ( `${ this . runtime . agentId } -${ timestamp } ` ) ;
93
- const originalMemory : Memory = {
94
- id : stringToUuid ( `${ roomId } -${ this . runtime . agentId } -${ timestamp } -original` ) ,
95
- userId : userIdUUID ,
96
- agentId : this . runtime . agentId ,
97
- content : {
98
- text : `No memories found, starting to initialize repository and create memories.` ,
99
- action : "NOTHING" ,
100
- source : "github" ,
101
- inReplyTo : stringToUuid ( `${ roomId } -${ this . runtime . agentId } ` )
102
- } ,
103
- roomId,
104
- createdAt : timestamp ,
105
- }
106
- let originalState = await this . runtime . composeState ( originalMemory ) ;
107
- originalState = await incorporateRepositoryState ( originalState , this . runtime , originalMemory , [ ] ) ;
108
- const initializeRepositoryMemory : Memory = {
109
- id : stringToUuid ( `${ roomId } -${ this . runtime . agentId } -${ timestamp } -initialize-repository` ) ,
110
- userId : userIdUUID ,
111
- agentId : this . runtime . agentId ,
112
- content : {
113
- text : `Initialize the repository ${ owner } /${ repository } on sif-dev branch` ,
114
- action : "INITIALIZE_REPOSITORY" ,
115
- source : "github" ,
116
- inReplyTo : stringToUuid ( `${ roomId } -${ this . runtime . agentId } ` )
117
- } ,
118
- roomId,
119
- createdAt : timestamp ,
120
- }
121
- await this . runtime . messageManager . createMemory ( initializeRepositoryMemory ) ;
122
- elizaLogger . debug ( "Memory created successfully:" , {
123
- memoryId : initializeRepositoryMemory . id ,
124
- action : initializeRepositoryMemory . content . action ,
125
- userId : this . runtime . agentId ,
126
- } ) ;
127
- const createMemoriesFromFilesMemory = {
128
- id : stringToUuid ( `${ roomId } -${ this . runtime . agentId } -${ timestamp } -create-memories-from-files` ) ,
129
- userId : userIdUUID ,
130
- agentId : this . runtime . agentId ,
131
- content : {
132
- text : `Create memories from files for the repository ${ owner } /${ repository } at path '/'` ,
133
- action : "CREATE_MEMORIES_FROM_FILES" ,
134
- source : "github" ,
135
- inReplyTo : stringToUuid ( `${ roomId } -${ this . runtime . agentId } ` )
136
- } ,
137
- roomId,
138
- createdAt : timestamp ,
139
- }
140
- await this . runtime . messageManager . createMemory ( createMemoriesFromFilesMemory ) ;
141
- elizaLogger . debug ( "Memory created successfully:" , {
142
- memoryId : createMemoriesFromFilesMemory . id ,
143
- action : createMemoriesFromFilesMemory . content . action ,
144
- userId : this . runtime . agentId ,
145
- } ) ;
146
- const callback : HandlerCallback = async (
147
- content : Content ,
148
- files : any [ ]
149
- ) => {
150
- elizaLogger . log ( "Callback called with content:" , content ) ;
151
- return [ ] ;
152
- } ;
153
- await this . runtime . processActions (
154
- originalMemory ,
155
- [ initializeRepositoryMemory , createMemoriesFromFilesMemory ] ,
156
- originalState ,
157
- callback
158
- ) ;
91
+ await this . initializeRepositoryAndCreateMemories ( owner , repository , roomId ) ;
159
92
}
160
93
161
94
elizaLogger . log ( 'Before composeState' )
162
95
const originalMemory = {
163
96
userId : this . runtime . agentId , // TODO: this should be the user id
164
97
roomId : roomId ,
165
98
agentId : this . runtime . agentId ,
166
- content : { text : "sample text " , action : "NOTHING" , source : "github" } ,
99
+ content : { text : "Initializing repository and creating memories " , action : "NOTHING" , source : "github" } ,
167
100
} as Memory ;
168
101
let originalState = await this . runtime . composeState ( originalMemory , { } ) ;
169
102
originalState = await incorporateRepositoryState ( originalState , this . runtime , originalMemory , [ ] ) ;
@@ -214,13 +147,6 @@ export class GitHubClient extends EventEmitter {
214
147
} ;
215
148
elizaLogger . log ( "New memory to be created:" , newMemory ) ;
216
149
217
- const responseContent = await generateMessageResponse ( {
218
- runtime : this . runtime ,
219
- context,
220
- modelClass : ModelClass . LARGE ,
221
- } ) ;
222
- elizaLogger . log ( "Generated response content:" , responseContent ) ;
223
-
224
150
try {
225
151
await this . runtime . messageManager . createMemory ( newMemory ) ;
226
152
elizaLogger . debug ( "Memory created successfully:" , {
@@ -262,6 +188,76 @@ export class GitHubClient extends EventEmitter {
262
188
elizaLogger . log ( "OODA cycle completed." ) ;
263
189
}
264
190
191
+ private async initializeRepositoryAndCreateMemories ( owner : string , repository : string , roomId : UUID ) {
192
+ elizaLogger . log ( "No memories found, skipping OODA cycle." ) ;
193
+ // time to initialize repository and create memories
194
+ const timestamp = Date . now ( ) ;
195
+ const userIdUUID = stringToUuid ( `${ this . runtime . agentId } -${ timestamp } ` ) ;
196
+ const originalMemory : Memory = {
197
+ id : stringToUuid ( `${ roomId } -${ this . runtime . agentId } -${ timestamp } -original` ) ,
198
+ userId : userIdUUID ,
199
+ agentId : this . runtime . agentId ,
200
+ content : {
201
+ text : `No memories found, starting to initialize repository and create memories.` ,
202
+ action : "NOTHING" ,
203
+ source : "github" ,
204
+ inReplyTo : stringToUuid ( `${ roomId } -${ this . runtime . agentId } ` )
205
+ } ,
206
+ roomId,
207
+ createdAt : timestamp ,
208
+ }
209
+ let originalState = await this . runtime . composeState ( originalMemory ) ;
210
+ originalState = await incorporateRepositoryState ( originalState , this . runtime , originalMemory , [ ] ) ;
211
+ const initializeRepositoryMemory : Memory = {
212
+ id : stringToUuid ( `${ roomId } -${ this . runtime . agentId } -${ timestamp } -initialize-repository` ) ,
213
+ userId : userIdUUID ,
214
+ agentId : this . runtime . agentId ,
215
+ content : {
216
+ text : `Initialize the repository ${ owner } /${ repository } on sif-dev branch` ,
217
+ action : "INITIALIZE_REPOSITORY" ,
218
+ source : "github" ,
219
+ inReplyTo : stringToUuid ( `${ roomId } -${ this . runtime . agentId } ` )
220
+ } ,
221
+ roomId,
222
+ createdAt : timestamp ,
223
+ }
224
+ await this . runtime . messageManager . createMemory ( initializeRepositoryMemory ) ;
225
+ elizaLogger . debug ( "Memory created successfully:" , {
226
+ memoryId : initializeRepositoryMemory . id ,
227
+ action : initializeRepositoryMemory . content . action ,
228
+ userId : this . runtime . agentId ,
229
+ } ) ;
230
+ const createMemoriesFromFilesMemory = {
231
+ id : stringToUuid ( `${ roomId } -${ this . runtime . agentId } -${ timestamp } -create-memories-from-files` ) ,
232
+ userId : userIdUUID ,
233
+ agentId : this . runtime . agentId ,
234
+ content : {
235
+ text : `Create memories from files for the repository ${ owner } /${ repository } at path '/'` ,
236
+ action : "CREATE_MEMORIES_FROM_FILES" ,
237
+ source : "github" ,
238
+ inReplyTo : stringToUuid ( `${ roomId } -${ this . runtime . agentId } ` )
239
+ } ,
240
+ roomId,
241
+ createdAt : timestamp ,
242
+ }
243
+ await this . runtime . messageManager . createMemory ( createMemoriesFromFilesMemory ) ;
244
+ elizaLogger . debug ( "Memory created successfully:" , {
245
+ memoryId : createMemoriesFromFilesMemory . id ,
246
+ action : createMemoriesFromFilesMemory . content . action ,
247
+ userId : this . runtime . agentId ,
248
+ } ) ;
249
+ const issuesMemories = await saveIssuesToMemory ( this . runtime , owner , repository , this . apiToken ) ;
250
+ elizaLogger . log ( "Issues memories:" , issuesMemories ) ;
251
+ const pullRequestsMemories = await savePullRequestsToMemory ( this . runtime , owner , repository , this . apiToken ) ;
252
+ elizaLogger . log ( "Pull requests memories:" , pullRequestsMemories ) ;
253
+
254
+ await this . runtime . processActions (
255
+ originalMemory ,
256
+ [ initializeRepositoryMemory , createMemoriesFromFilesMemory ] ,
257
+ originalState ,
258
+ undefined
259
+ ) ;
260
+ }
265
261
}
266
262
267
263
export const GitHubClientInterface : Client = {
@@ -282,4 +278,6 @@ export const GitHubClientInterface: Client = {
282
278
} ,
283
279
} ;
284
280
281
+ export * from "./utils" ;
282
+
285
283
export default GitHubClientInterface ;
0 commit comments