Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: scope email account lookups by workspace (#198)
Gustavo Ye5d8db880e404
diff --git a/src/email-worker/src/index.ts b/src/email-worker/src/index.tsindex a287a5b7c..afa586144 100644--- a/src/email-worker/src/index.ts+++ b/src/email-worker/src/index.ts@@ -267,15 +267,16 @@ export default {}if (action === "test" && request.method === "POST") {- return this.handleTestConnection(accountId, env)+ const workspaceId = url.searchParams.get("workspaceId") ?? undefined+ return this.handleTestConnection(accountId, env, workspaceId)}return Response.json({ error: "not found" }, { status: 404 })},- async handleTestConnection(accountId: string, env: EmailEnv): Promise<Response> {+ async handleTestConnection(accountId: string, env: EmailEnv, workspaceId?: string): Promise<Response> {const db = createDb(env.DB)- const account = await queries.emailAccount.getEmailAccountById(db, accountId)+ const account = await queries.emailAccount.getEmailAccountById(db, accountId, workspaceId)if (!account) {return Response.json({ error: "account not found" }, { status: 404 })}diff --git a/src/shared/src/db/queries/email-account.ts b/src/shared/src/db/queries/email-account.tsindex 907edf044..60db79d17 100644--- a/src/shared/src/db/queries/email-account.ts+++ b/src/shared/src/db/queries/email-account.ts@@ -46,11 +46,13 @@ export async function getEmailAccountScoped(db: Database, id: string, agentId: sreturn rows[0] ?? null;}-export async function getEmailAccountById(db: Database, id: string) {+export async function getEmailAccountById(db: Database, id: string, workspaceId?: string) {+ const conditions = [eq(agentEmailAccount.id, id)];+ if (workspaceId) conditions.push(eq(agentEmailAccount.workspaceId, workspaceId));const rows = await db.select().from(agentEmailAccount)- .where(eq(agentEmailAccount.id, id));+ .where(and(...conditions));return rows[0] ?? null;}diff --git a/src/web/src/app/api/agents/[id]/email-accounts/[accountId]/test/route.ts b/src/web/src/app/api/agents/[id]/email-accounts/[accountId]/test/route.tsindex 08dcfea7a..6e5de5ba5 100644--- a/src/web/src/app/api/agents/[id]/email-accounts/[accountId]/test/route.ts+++ b/src/web/src/app/api/agents/[id]/email-accounts/[accountId]/test/route.ts@@ -22,11 +22,11 @@ export const POST = withAuth(async (req, ctx) => {let testRes: Responsetry {- testRes = await cfEnv.EMAIL_WORKER.fetch(`http://internal/imap/test?accountId=${accountId}`, {+ testRes = await cfEnv.EMAIL_WORKER.fetch(`http://internal/imap/test?accountId=${accountId}&workspaceId=${ws.workspaceId}`, {method: "POST",})} catch {- testRes = await fetch(`${DEV_EMAIL_WORKER_URL}/imap/test?accountId=${accountId}`, {+ testRes = await fetch(`${DEV_EMAIL_WORKER_URL}/imap/test?accountId=${accountId}&workspaceId=${ws.workspaceId}`, {method: "POST",})}