Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix authorization header check; Fix db deployment auth field format

Tomas Valenta3f576b65995f
diff --git a/pages/api/agent/index.ts b/pages/api/agent/index.ts
index b1f966fd1..126303281 100644
--- a/pages/api/agent/index.ts
+++ b/pages/api/agent/index.ts
@@ -9,16 +9,18 @@ import { PostAgentBody } from 'pages/agent/smol-developer/setup'
import { getGHInstallationClient } from 'github/installationClient'
import { createAgentDeployment, createPR, getGHAccessToken, getGHAppInfo, triggerSmolDevAgentRun } from 'github/pullRequest'
-export interface GitHubAuthData {
- app_name: string,
- app_email: string,
- installation_id: number,
- repository_id: number,
- issue_id: number,
- pull_number: number,
- branch: string,
- owner: string,
- repo: string,
+export interface DeploymentAuthData {
+ github: {
+ app_name: string,
+ app_email: string,
+ installation_id: number,
+ repository_id: number,
+ issue_id: number,
+ pull_number: number,
+ branch: string,
+ owner: string,
+ repo: string,
+ }
}
async function postAgent(req: NextApiRequest, res: NextApiResponse) {
@@ -87,24 +89,26 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
const appInfo = await appInfoPromise
+ const authData: DeploymentAuthData = {
+ github: {
+ app_name: appInfo.name,
+ app_email: appInfo.email,
+ installation_id: installationID,
+ repository_id: repositoryID,
+ issue_id: issueID,
+ pull_number: pullNumber,
+ branch,
+ owner,
+ repo,
+ },
+ }
+
const project = await prisma.projects.create({
data: {
id: nanoid(),
deployments: {
create: {
- auth: {
- github: {
- app_name: appInfo.name,
- app_email: appInfo.email,
- installation_id: installationID,
- repository_id: repositoryID,
- issue_id: issueID,
- pull_number: pullNumber,
- branch,
- owner,
- repo,
- },
- },
+ auth: authData as any,
enabled: false,
},
},
@@ -179,7 +183,7 @@ async function handler(
return
}
- res.setHeader('Allow', ['POST'])
+ res.setHeader('Allow', 'POST')
res.status(405).json({ statusCode: 405, message: 'Method Not Allowed' })
return
}
diff --git a/pages/api/agent/run.ts b/pages/api/agent/run.ts
index 8d5f6cf23..151d29684 100644
--- a/pages/api/agent/run.ts
+++ b/pages/api/agent/run.ts
@@ -3,7 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from 'db/prisma'
import { getGHInstallationClient } from 'github/installationClient'
import { addCommentToPR } from 'github/pullRequest'
-import { GitHubAuthData } from '.'
+import { DeploymentAuthData } from '.'
// Indicate that the agent state changed (run finished)
@@ -14,10 +14,11 @@ async function postRun(req: NextApiRequest, res: NextApiResponse) {
} = req.body as { prompt: string, deployment_id: string }
- const header = req.headers['Authorization'] as string | undefined
+ const header = req.headers.authorization
// Extract the token from the header
const token = header?.split(' ')[1]
if (process.env.SECRET_TOKEN && token !== process.env.SECRET_TOKEN) {
+ console.log('Invalid token', token, process.env.SECRET_TOKEN)
throw new Error('Invalid token')
}
@@ -30,8 +31,8 @@ async function postRun(req: NextApiRequest, res: NextApiResponse) {
},
})
- const ghData = deployment.auth as unknown as GitHubAuthData
- const client = getGHInstallationClient({ installationID: ghData.installation_id })
+ const authData = deployment.auth as unknown as DeploymentAuthData
+ const client = getGHInstallationClient({ installationID: authData.github.installation_id })
// TODO: Should we maybe just edit the previous comment?
@@ -39,9 +40,9 @@ async function postRun(req: NextApiRequest, res: NextApiResponse) {
await addCommentToPR({
body: 'Finished running the agent',
client,
- owner: ghData.owner,
- repo: ghData.repo,
- pullNumber: ghData.pull_number,
+ owner: authData.github.owner,
+ repo: authData.github.repo,
+ pullNumber: authData.github.pull_number,
})
}
@@ -51,10 +52,11 @@ async function deleteRun(req: NextApiRequest, res: NextApiResponse) {
deployment_id,
} = req.body as { deployment_id: string }
- const header = req.headers['Authorization'] as string | undefined
+ const header = req.headers.authorization
// Extract the token from the header
const token = header?.split(' ')[1]
if (process.env.SECRET_TOKEN && token !== process.env.SECRET_TOKEN) {
+ console.log('Invalid token', token, process.env.SECRET_TOKEN)
throw new Error('Invalid token')
}
@@ -64,17 +66,17 @@ async function deleteRun(req: NextApiRequest, res: NextApiResponse) {
},
})
- const ghData = deployment.auth as unknown as GitHubAuthData
- const client = getGHInstallationClient({ installationID: ghData.installation_id })
+ const authData = deployment.auth as unknown as DeploymentAuthData
+ const client = getGHInstallationClient({ installationID: authData.github.installation_id })
// Add comment about the run being cancelled
// TODO: Maybe just edit the previous comment?
await addCommentToPR({
body: 'Run cancelled',
client,
- owner: ghData.owner,
- repo: ghData.repo,
- pullNumber: ghData.pull_number,
+ owner: authData.github.owner,
+ repo: authData.github.repo,
+ pullNumber: authData.github.pull_number,
})
}