Skip to content

Commit 781e641

Browse files
authored
Merge pull request #147 from Sifchain/realitySpiral/gitClient
feat: reimplement add comment to issues + prs and generate useful content
2 parents 5e5016b + 4f96136 commit 781e641

15 files changed

+834
-334
lines changed

packages/client-github/src/index.ts

+77-79
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import {
1010
modifyIssueAction,
1111
addCommentToIssueAction,
1212
ideationAction,
13+
addCommentToPRAction,
1314
incorporateRepositoryState,
1415
getRepositoryRoomId
1516
} from "@elizaos/plugin-github";
1617
import { isOODAContent, OODAContent, OODASchema } from "./types";
1718
import { oodaTemplate } from "./templates";
19+
import { saveIssuesToMemory, savePullRequestsToMemory } from "./utils";
1820

1921
export class GitHubClient extends EventEmitter {
2022
apiToken: string;
@@ -37,7 +39,7 @@ export class GitHubClient extends EventEmitter {
3739
this.runtime.registerAction(modifyIssueAction);
3840
this.runtime.registerAction(addCommentToIssueAction);
3941
this.runtime.registerAction(ideationAction);
40-
42+
this.runtime.registerAction(addCommentToPRAction);
4143
elizaLogger.log("GitHubClient actions and providers registered.");
4244

4345
// Start the OODA loop after initialization
@@ -86,84 +88,15 @@ export class GitHubClient extends EventEmitter {
8688
);
8789
// elizaLogger.log("Retrieved memories:", memories);
8890
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);
15992
}
16093

16194
elizaLogger.log('Before composeState')
16295
const originalMemory = {
16396
userId: this.runtime.agentId, // TODO: this should be the user id
16497
roomId: roomId,
16598
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" },
167100
} as Memory;
168101
let originalState = await this.runtime.composeState(originalMemory, {});
169102
originalState = await incorporateRepositoryState(originalState, this.runtime, originalMemory, []);
@@ -214,13 +147,6 @@ export class GitHubClient extends EventEmitter {
214147
};
215148
elizaLogger.log("New memory to be created:", newMemory);
216149

217-
const responseContent = await generateMessageResponse({
218-
runtime: this.runtime,
219-
context,
220-
modelClass: ModelClass.LARGE,
221-
});
222-
elizaLogger.log("Generated response content:", responseContent);
223-
224150
try {
225151
await this.runtime.messageManager.createMemory(newMemory);
226152
elizaLogger.debug("Memory created successfully:", {
@@ -262,6 +188,76 @@ export class GitHubClient extends EventEmitter {
262188
elizaLogger.log("OODA cycle completed.");
263189
}
264190

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+
}
265261
}
266262

267263
export const GitHubClientInterface: Client = {
@@ -282,4 +278,6 @@ export const GitHubClientInterface: Client = {
282278
},
283279
};
284280

281+
export * from "./utils";
282+
285283
export default GitHubClientInterface;

0 commit comments

Comments
 (0)