-
Notifications
You must be signed in to change notification settings - Fork 258
feat(web): customisable AI code review agent configs #1143
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| -- CreateEnum | ||
| CREATE TYPE "AgentType" AS ENUM ('CODE_REVIEW'); | ||
|
|
||
| -- CreateEnum | ||
| CREATE TYPE "AgentScope" AS ENUM ('ORG', 'CONNECTION', 'REPO'); | ||
|
|
||
| -- CreateEnum | ||
| CREATE TYPE "PromptMode" AS ENUM ('REPLACE', 'APPEND'); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "AgentConfig" ( | ||
| "id" TEXT NOT NULL, | ||
| "orgId" INTEGER NOT NULL, | ||
| "name" TEXT NOT NULL, | ||
| "description" TEXT, | ||
| "type" "AgentType" NOT NULL, | ||
| "enabled" BOOLEAN NOT NULL DEFAULT true, | ||
| "prompt" TEXT, | ||
| "promptMode" "PromptMode" NOT NULL DEFAULT 'APPEND', | ||
| "scope" "AgentScope" NOT NULL, | ||
| "settings" JSONB NOT NULL DEFAULT '{}', | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "AgentConfig_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "AgentConfigToRepo" ( | ||
| "agentConfigId" TEXT NOT NULL, | ||
| "repoId" INTEGER NOT NULL, | ||
|
|
||
| CONSTRAINT "AgentConfigToRepo_pkey" PRIMARY KEY ("agentConfigId","repoId") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "AgentConfigToConnection" ( | ||
| "agentConfigId" TEXT NOT NULL, | ||
| "connectionId" INTEGER NOT NULL, | ||
|
|
||
| CONSTRAINT "AgentConfigToConnection_pkey" PRIMARY KEY ("agentConfigId","connectionId") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "AgentConfig_orgId_type_enabled_idx" ON "AgentConfig"("orgId", "type", "enabled"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "AgentConfig_orgId_name_key" ON "AgentConfig"("orgId", "name"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "AgentConfig" ADD CONSTRAINT "AgentConfig_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "AgentConfigToRepo" ADD CONSTRAINT "AgentConfigToRepo_agentConfigId_fkey" FOREIGN KEY ("agentConfigId") REFERENCES "AgentConfig"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "AgentConfigToRepo" ADD CONSTRAINT "AgentConfigToRepo_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "AgentConfigToConnection" ADD CONSTRAINT "AgentConfigToConnection_agentConfigId_fkey" FOREIGN KEY ("agentConfigId") REFERENCES "AgentConfig"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "AgentConfigToConnection" ADD CONSTRAINT "AgentConfigToConnection_connectionId_fkey" FOREIGN KEY ("connectionId") REFERENCES "Connection"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||
| import { authenticatedPage } from "@/middleware/authenticatedPage"; | ||||||||||||||||||
| import { NavigationMenu } from "@/app/(app)/components/navigationMenu"; | ||||||||||||||||||
| import { AgentConfigForm } from "../agentConfigForm"; | ||||||||||||||||||
| import { notFound } from "next/navigation"; | ||||||||||||||||||
| import { OrgRole } from "@sourcebot/db"; | ||||||||||||||||||
|
|
||||||||||||||||||
| type Props = { | ||||||||||||||||||
| params: Promise<{ agentId: string }>; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| export default authenticatedPage(async ({ prisma, org }, { params }: Props) => { | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gate config editing to org owners. This page exposes the edit form and config details with plain authentication. Add the owner-role option to Proposed fix+import { OrgRole } from "@sourcebot/db";
...
-export default authenticatedPage(async ({ prisma, org }, { params }: Props) => {
+export default authenticatedPage(async ({ prisma, org }, { params }: Props) => {
const { agentId } = await params;
...
-});
+}, { minRole: OrgRole.OWNER, redirectTo: "/settings" });Based on learnings: Use 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| const { agentId } = await params; | ||||||||||||||||||
|
|
||||||||||||||||||
| const [config, connections, repos] = await Promise.all([ | ||||||||||||||||||
| prisma.agentConfig.findFirst({ | ||||||||||||||||||
| where: { id: agentId, orgId: org.id }, | ||||||||||||||||||
| include: { | ||||||||||||||||||
| repos: { select: { repoId: true } }, | ||||||||||||||||||
| connections: { select: { connectionId: true } }, | ||||||||||||||||||
| }, | ||||||||||||||||||
| }), | ||||||||||||||||||
| prisma.connection.findMany({ | ||||||||||||||||||
| where: { orgId: org.id }, | ||||||||||||||||||
| select: { id: true, name: true, connectionType: true }, | ||||||||||||||||||
| orderBy: { name: "asc" }, | ||||||||||||||||||
| }), | ||||||||||||||||||
| prisma.repo.findMany({ | ||||||||||||||||||
| where: { orgId: org.id }, | ||||||||||||||||||
| select: { id: true, displayName: true, external_id: true, external_codeHostType: true }, | ||||||||||||||||||
| orderBy: { displayName: "asc" }, | ||||||||||||||||||
| }), | ||||||||||||||||||
| ]); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!config) { | ||||||||||||||||||
| notFound(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <div className="flex flex-col items-center overflow-hidden min-h-screen"> | ||||||||||||||||||
| <NavigationMenu /> | ||||||||||||||||||
| <div className="w-full max-w-3xl px-4 mt-12 mb-24"> | ||||||||||||||||||
| <h1 className="text-2xl font-semibold text-foreground mb-8">Edit agent config</h1> | ||||||||||||||||||
| <AgentConfigForm | ||||||||||||||||||
| initialValues={{ | ||||||||||||||||||
| id: config.id, | ||||||||||||||||||
| name: config.name, | ||||||||||||||||||
| description: config.description ?? "", | ||||||||||||||||||
| type: config.type, | ||||||||||||||||||
| enabled: config.enabled, | ||||||||||||||||||
| prompt: config.prompt ?? "", | ||||||||||||||||||
| promptMode: config.promptMode, | ||||||||||||||||||
| scope: config.scope, | ||||||||||||||||||
| repoIds: config.repos.map((r) => r.repoId), | ||||||||||||||||||
| connectionIds: config.connections.map((c) => c.connectionId), | ||||||||||||||||||
| settings: config.settings as Record<string, unknown>, | ||||||||||||||||||
| }} | ||||||||||||||||||
| connections={connections} | ||||||||||||||||||
| repos={repos} | ||||||||||||||||||
| /> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| </div> | ||||||||||||||||||
| ); | ||||||||||||||||||
| }, { minRole: OrgRole.OWNER, redirectTo: '/agents' }); | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 50380
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 1716
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 836
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 142
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 2432
Add tenant constraints and reverse lookup indexes to AgentConfig mapping tables.
The migration does not include the recommended protections. The junction tables (
AgentConfigToRepoandAgentConfigToConnection) lackorgIdcolumns, so the database cannot enforce that a mapped repo or connection belongs to the same organization as theAgentConfig. While the API validates this at the application layer, the invariant should be protected at the schema layer to prevent data corruption from regressions or bypass.Additionally, the composite primary keys are
agentConfigId-first, but typical query patterns filter byrepoIdorconnectionIdfirst. Without reverse indexes, these lookups will perform full table scans or inefficient index usage.Add
orgIdcolumn with tenant-safe constraints and create reverse indexes such as@@index([repoId, agentConfigId])and@@index([connectionId, agentConfigId])to both tables.🤖 Prompt for AI Agents