36 lines · 1.9 KBRaw
| 1 | export { cliApi } from "./cli.ts"; |
| 2 | export { RepoHub, UserHub, withHints } from "./hub.ts"; |
| 3 | export { mcpApi } from "./mcp.ts"; |
| 4 | export { consumePushes, processPush, reconcilePushes, type PushMessage } from "./pushes.ts"; |
| 5 | export { agentProgressForCi, consumeAgentRuns, consumeDeadAgentRuns, startAgentForCi, type AgentRunMessage } from "./agent-runs.ts"; |
| 6 | export { agentRepo } from "./handles/refs.ts"; |
| 7 | import type { Backend } from "./contract/handles.ts"; |
| 8 | import { readCookie, resolveActor } from "./identity.ts"; |
| 9 | import { NAMESPACE_COOKIE } from "./contract/limits.ts"; |
| 10 | import { Policy } from "./policy.ts"; |
| 11 | import { memberNamespaces, namespaceBySlug, namespacePolicy } from "./repos.ts"; |
| 12 | import { openAgentConsent } from "./oauth.ts"; |
| 13 | import { serveApi } from "./sessions.ts"; |
| 14 | import { openGate } from "./handles/gate.ts"; |
| 15 | import { openRefs } from "./handles/refs.ts"; |
| 16 | import { serveGit } from "./serve-git.ts"; |
| 17 | import { serveLive } from "./serve-live.ts"; |
| 18 | |
| 19 | export function createBackend(env: Env, ctx: ExecutionContext): Backend { |
| 20 | return { |
| 21 | async refs(request, namespace) { |
| 22 | const { actor } = await resolveActor(env.DB, ctx, request); |
| 23 | const base = new Policy(actor, null); |
| 24 | const mine = await memberNamespaces(env.DB, actor); |
| 25 | const preferred = readCookie(request, NAMESPACE_COOKIE); |
| 26 | const home = namespace ? await namespaceBySlug(env.DB, namespace) : (mine.find((candidate) => candidate.slug === preferred) ?? mine[0] ?? null); |
| 27 | const policy = home ? await namespacePolicy(env.DB, base, home.id) : base; |
| 28 | return openRefs({ env, ctx, origin: new URL(request.url).origin }, policy, home, mine); |
| 29 | }, |
| 30 | gate: () => openGate(env, ctx), |
| 31 | git: (request) => serveGit(env, ctx, request), |
| 32 | api: (request) => serveApi(env, ctx, request), |
| 33 | live: (request) => serveLive(env, ctx, request), |
| 34 | agentConsent: (request) => openAgentConsent(env, ctx, request), |
| 35 | }; |
| 36 | } |