Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github create and modify issue and add comment to issue act… #96

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ import {
githubCreateCommitPlugin,
githubCreatePullRequestPlugin,
githubCreateMemorizeFromFilesPlugin,
} from "@ai16z/plugin-github"
githubCreateIssuePlugin,
githubModifyIssuePlugin,
githubAddCommentToIssuePlugin,
} from "@ai16z/plugin-github";
import Database from "better-sqlite3";
import fs from "fs";
import path from "path";
Expand Down Expand Up @@ -412,18 +415,30 @@ export function createAgent(
: null,
...(getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY")
? [coinbaseMassPaymentsPlugin, tradePlugin, tokenContractPlugin, advancedTradePlugin]
? [
coinbaseMassPaymentsPlugin,
tradePlugin,
tokenContractPlugin,
advancedTradePlugin,
]
: []),
getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
? webhookPlugin
: null,
getSecret(character, "WALLET_SECRET_SALT") ? teePlugin : null,
getSecret(character, "GITHUB_API_TOKEN") ? githubInitializePlugin : null,
getSecret(character, "GITHUB_API_TOKEN") ? githubCreateCommitPlugin : null,
getSecret(character, "GITHUB_API_TOKEN") ? githubCreatePullRequestPlugin : null,
getSecret(character, "GITHUB_API_TOKEN") ? githubCreateMemorizeFromFilesPlugin : null,
...(getSecret(character, "GITHUB_API_TOKEN")
? [
githubInitializePlugin,
githubCreateCommitPlugin,
githubCreatePullRequestPlugin,
githubCreateMemorizeFromFilesPlugin,
githubCreateIssuePlugin,
githubModifyIssuePlugin,
githubAddCommentToIssuePlugin,
]
: []),
getSecret(character, "ALCHEMY_API_KEY") ? goatPlugin : null,
getSecret(character, "FLOW_ADDRESS") &&
getSecret(character, "FLOW_PRIVATE_KEY")
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import { githubInitializePlugin } from "./plugins/initializeRepository";
import { githubCreateMemorizeFromFilesPlugin } from "./plugins/createMemoriesFromFiles";
import { githubCreatePullRequestPlugin } from "./plugins/createPullRequest";
import { githubCreateCommitPlugin } from "./plugins/createCommit";
import { githubCreateIssuePlugin } from "./plugins/createIssue";
import { githubModifyIssuePlugin } from "./plugins/modifyIssue";
import { githubAddCommentToIssuePlugin } from "./plugins/addCommentToIssue";

export const plugins = {
githubInitializePlugin,
githubCreateMemorizeFromFilesPlugin,
githubCreatePullRequestPlugin,
githubCreateCommitPlugin,
githubCreateIssuePlugin,
githubModifyIssuePlugin,
githubAddCommentToIssuePlugin,
};

export * from "./plugins/initializeRepository";
export * from "./plugins/createMemoriesFromFiles";
export * from "./plugins/createPullRequest";
export * from "./plugins/createCommit";
export * from "./plugins/createIssue";
export * from "./plugins/modifyIssue";
export * from "./plugins/addCommentToIssue";
127 changes: 127 additions & 0 deletions packages/plugin-github/src/plugins/addCommentToIssue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {
composeContext,
elizaLogger,
generateObjectV2,
Action,
HandlerCallback,
IAgentRuntime,
Memory,
ModelClass,
Plugin,
State,
} from "@ai16z/eliza";
import { GitHubService } from "../services/github";
import {
AddCommentToIssueContent,
AddCommentToIssueSchema,
isAddCommentToIssueContent,
} from "../types";
import { addCommentToIssueTemplate } from "../templates";

export const addCommentToIssueAction: Action = {
name: "ADD_COMMENT_TO_ISSUE",
similes: [
"ADD_COMMENT_TO_ISSUE",
"COMMENT_ON_ISSUE",
"POST_COMMENT",
"ADD_COMMENT",
],
description: "Adds a comment to an existing issue in the GitHub repository",
validate: async (runtime: IAgentRuntime) => {
const token = !!runtime.getSetting("GITHUB_API_TOKEN");
return token;
},
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State,
options: any,
callback: HandlerCallback
) => {
elizaLogger.log("Composing state for message:", message);
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

const context = composeContext({
state,
template: addCommentToIssueTemplate,
});

const details = await generateObjectV2({
runtime,
context,
modelClass: ModelClass.SMALL,
schema: AddCommentToIssueSchema,
});

if (!isAddCommentToIssueContent(details.object)) {
elizaLogger.error("Invalid content:", details.object);
throw new Error("Invalid content");
}

const content = details.object as AddCommentToIssueContent;

elizaLogger.info("Adding comment to issue in the repository...");

const githubService = new GitHubService({
owner: content.owner,
repo: content.repo,
auth: runtime.getSetting("GITHUB_API_TOKEN"),
});

try {
const comment = await githubService.addIssueComment(
content.issue,
content.comment
);

elizaLogger.info(
`Added comment to issue #${content.issue} successfully!`
);

callback({
text: `Added comment to issue #${content.issue} successfully!`,
attachments: [],
});
} catch (error) {
elizaLogger.error(
`Error adding comment to issue #${content.issue} in repository ${content.owner}/${content.repo}:`,
error
);
callback(
{
text: `Error adding comment to issue #${content.issue}. Please try again.`,
},
[]
);
}
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "Add a comment to issue #1 in repository user1/repo1: 'This is fixed in the latest release'",
},
},
{
user: "{{agentName}}",
content: {
text: "Added comment to issue #1 successfully!",
action: "ADD_COMMENT",
},
},
],
],
};

export const githubAddCommentToIssuePlugin: Plugin = {
name: "githubAddCommentToIssue",
description: "Integration with GitHub for adding comments to issues",
actions: [addCommentToIssueAction],
evaluators: [],
providers: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to add a provider that shows all the comments for an issue can be a follow up not urgent

};
13 changes: 1 addition & 12 deletions packages/plugin-github/src/plugins/createCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import {
isCreateCommitContent,
} from "../types";
import { commitAndPushChanges, getRepoPath, writeFiles } from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export const createCommitAction: Action = {
name: "CREATE_COMMIT",
Expand Down Expand Up @@ -205,11 +200,5 @@ export const githubCreateCommitPlugin: Plugin = {
"Integration with GitHub for committing changes to the repository",
actions: [createCommitAction],
evaluators: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
providers: [],
};
123 changes: 123 additions & 0 deletions packages/plugin-github/src/plugins/createIssue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import {
composeContext,
elizaLogger,
generateObjectV2,
Action,
HandlerCallback,
IAgentRuntime,
Memory,
ModelClass,
Plugin,
State,
} from "@ai16z/eliza";
import { GitHubService } from "../services/github";
import { createIssueTemplate } from "../templates";
import {
CreateIssueContent,
CreateIssueSchema,
isCreateIssueContent,
} from "../types";

export const createIssueAction: Action = {
name: "CREATE_ISSUE",
similes: ["CREATE_ISSUE", "GITHUB_CREATE_ISSUE", "OPEN_ISSUE"],
description: "Creates a new issue in the GitHub repository",
validate: async (runtime: IAgentRuntime) => {
const token = !!runtime.getSetting("GITHUB_API_TOKEN");
return token;
},
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State,
options: any,
callback: HandlerCallback
) => {
elizaLogger.log("Composing state for message:", message);
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

const context = composeContext({
state,
template: createIssueTemplate,
});

const details = await generateObjectV2({
runtime,
context,
modelClass: ModelClass.SMALL,
schema: CreateIssueSchema,
});

if (!isCreateIssueContent(details.object)) {
elizaLogger.error("Invalid content:", details.object);
throw new Error("Invalid content");
}

const content = details.object as CreateIssueContent;

elizaLogger.info("Creating issue in the repository...");

const githubService = new GitHubService({
owner: content.owner,
repo: content.repo,
auth: runtime.getSetting("GITHUB_API_TOKEN"),
});

try {
const issue = await githubService.createIssue(
content.title,
content.body,
content.labels
);

elizaLogger.info(
`Created issue successfully! Issue number: ${issue.number}`
);

callback({
text: `Created issue #${issue.number} successfully!`,
attachments: [],
});
} catch (error) {
elizaLogger.error(
`Error creating issue in repository ${content.owner}/${content.repo}:`,
error
);
callback(
{
text: `Error creating issue in repository ${content.owner}/${content.repo}. Please try again.`,
},
[]
);
}
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "Create an issue in repository user1/repo1 titled 'Bug: Application crashes on startup'",
},
},
{
user: "{{agentName}}",
content: {
text: "Created issue #1 successfully!",
action: "CREATE_ISSUE",
},
},
],
],
};

export const githubCreateIssuePlugin: Plugin = {
name: "githubCreateIssue",
description: "Integration with GitHub for creating issues in repositories",
actions: [createIssueAction],
evaluators: [],
providers: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here should be list of recent issues but not blocking

};
13 changes: 1 addition & 12 deletions packages/plugin-github/src/plugins/createMemoriesFromFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import {
isCreateMemoriesFromFilesContent,
} from "../types";
import { getRepoPath, retrieveFiles } from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export async function addFilesToMemory(
runtime: IAgentRuntime,
Expand Down Expand Up @@ -325,11 +320,5 @@ export const githubCreateMemorizeFromFilesPlugin: Plugin = {
description: "Integration with GitHub for creating memories from files",
actions: [createMemoriesFromFilesAction],
evaluators: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
providers: [],
};
13 changes: 1 addition & 12 deletions packages/plugin-github/src/plugins/createPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import {
getRepoPath,
writeFiles,
} from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export const createPullRequestAction: Action = {
name: "CREATE_PULL_REQUEST",
Expand Down Expand Up @@ -247,11 +242,5 @@ export const githubCreatePullRequestPlugin: Plugin = {
description: "Integration with GitHub for creating a pull request",
actions: [createPullRequestAction],
evaluators: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
providers: [],
};
Loading
Loading