Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add links and info to PR body and comments
Tomas Valenta1de12180f15e
diff --git a/github/pullRequest.ts b/github/pullRequest.tsindex 14931a4d5..680c832c1 100644--- a/github/pullRequest.ts+++ b/github/pullRequest.ts@@ -5,6 +5,7 @@ import api from 'api-client/api'import { deployments, prisma } from 'db/prisma'import { GitHubClient } from './client'+import { prInfoText } from 'pages/api/agent'const configuration = new Configuration({apiKey: process.env.OPENAI_API_KEY,@@ -172,7 +173,7 @@ export async function getPromptFromPR({.map(c => c.body).join('\n')- return `${prBody}\n\n${comments}`+ return `${prBody?.replace(prInfoText, '')}\n\n${comments}`}export async function getDeploymentsForPR({@@ -188,6 +189,11 @@ export async function getDeploymentsForPR({}) {return await prisma.deployments.findMany({include: {+ _count: {+ select: {+ log_files: true,+ },+ },projects: {include: {teams: {@@ -251,10 +257,14 @@ export async function triggerSmolDevAgentRun({prompt,accessToken,commitMessage,+ slug,owner,repo,pullNumber,+ totalRuns,}: {+ totalRuns: number,+ slug: string | null,pullNumber: number,client: GitHubClient,owner: string,@@ -264,10 +274,11 @@ export async function triggerSmolDevAgentRun({prompt: string,accessToken: string,}) {- console.log('Triggering smol dev agent run:', { owner, repo, pullNumber, prompt })+ if (!slug) throw new Error('slug is required')+ console.log('Triggering smol dev agent run:', { owner, repo, pullNumber, prompt })await addCommentToPR({- body: 'Started smol dev agent run',+ body: `Started smol developer [agent run](https://app.e2b.dev/logs/${slug}-run-${totalRuns}).`,client,owner,repo,diff --git a/github/webhooks.ts b/github/webhooks.tsindex 21c09c2d5..e215671ed 100644--- a/github/webhooks.ts+++ b/github/webhooks.ts@@ -240,6 +240,8 @@ const pullRequestEditHandler: HandlerFunction<'pull_request.edited', unknown> =owner,repo,client,+ totalRuns: d._count.log_files,+ slug: d.projects.slug,pullNumber: issueNumber,})@@ -336,6 +338,8 @@ const issueCommentHandler: HandlerFunction<'issue_comment', unknown> = async (evawait triggerSmolDevAgentRun({prompt,deployment: d,+ slug: d.projects.slug,+ totalRuns: d._count.log_files,accessToken,owner,repo,diff --git a/pages/api/agent/index.ts b/pages/api/agent/index.tsindex 6b1c0efb6..a7f9adacb 100644--- a/pages/api/agent/index.ts+++ b/pages/api/agent/index.ts@@ -34,6 +34,13 @@ export interface DeploymentAuthData {}}+export const prInfoText = `+---+*Add PR comments with additional instructions to trigger the agent again.*++*Powered by [e2b](https://app.e2b.dev/agent/smol-developer)*+`+async function postAgent(req: NextApiRequest, res: NextApiResponse) {const {installationID,@@ -93,13 +100,15 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {throw new Error('Generated PR title is empty')}+ const bodyWithInfo = `${body}${prInfoText}`+const { issueID, number: pullNumber, url: pullURL } = await createPR({client,title: prTitle,defaultBranch,branch,commitMessage,- body,+ body: bodyWithInfo,owner,repo,})@@ -205,6 +214,8 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {owner,repo,client,+ slug,+ totalRuns: 0,pullNumber,})diff --git a/pages/api/agent/run.ts b/pages/api/agent/run.tsindex c5b2ede4e..2b69280df 100644--- a/pages/api/agent/run.ts+++ b/pages/api/agent/run.ts@@ -37,6 +37,11 @@ async function postRun(req: NextApiRequest, res: NextApiResponse) {last_finished_prompt: prompt,},include: {+ _count: {+ select: {+ log_files: true,+ },+ },projects: {include: {teams: {@@ -59,7 +64,7 @@ async function postRun(req: NextApiRequest, res: NextApiResponse) {// TODO: Should we maybe just edit the previous comment?// Or should we do that only if the previous run was cancelledawait addCommentToPR({- body: 'Finished running the agent',+ body: `Finished smol developer [agent run](https://app.e2b.dev/logs/${deployment.projects.slug}-run-${deployment._count.log_files - 1}).`,client,owner: authData.github.owner,repo: authData.github.repo,@@ -122,6 +127,11 @@ async function deleteRun(req: NextApiRequest, res: NextApiResponse) {id: deployment_id,},include: {+ _count: {+ select: {+ log_files: true,+ },+ },projects: {include: {teams: {@@ -143,7 +153,7 @@ async function deleteRun(req: NextApiRequest, res: NextApiResponse) {// Add comment about the run being cancelledawait addCommentToPR({- body: 'Run cancelled',+ body: `Cancelled smol developer [agent run](https://app.e2b.dev/logs/${deployment.projects.slug}-run-${deployment._count.log_files - 1}).`,client,owner: authData.github.owner,repo: authData.github.repo,