An open-source, faster Devin alternative
TypeScript
api-edge: proxy the organization computer routes and its Slack app
Slack U06GFN8DJ7P14b52f162e09
diff --git a/cloudflare-workers/api-edge/src/computer.ts b/cloudflare-workers/api-edge/src/computer.tsnew file mode 100644index 00000000..757c59a8--- /dev/null+++ b/cloudflare-workers/api-edge/src/computer.ts@@ -0,0 +1,166 @@+// The organization's computer (serverless-agents-ws work 052). The dashboard+// calls `/api/dashboard/managed-agents/computer…`; the edge proxies those+// routes to the backend's `/v1/computer…` with its org assertion. They are+// dashboard-only in v1: the API-key mount `/api/managed-agents` refuses them.+//+// Response bodies are rebuilt field by field from the binding contract, so a+// contract body passes through unchanged while anything the backend adds+// beside it (where the machine runs, what size it is) never reaches a browser.++const COMPUTER_ROUTE = /^\/computer(?:\/|$)/;++export function isComputerRouteSuffix(suffix: string): boolean {+ return COMPUTER_ROUTE.test(suffix);+}++export function isComputerRoute(method: string, suffix: string): boolean {+ if ((method === "GET" || method === "POST") && suffix === "/computer") {+ return true;+ }+ if (method === "GET" && suffix === "/computer/sessions") return true;+ if (method === "POST" && suffix === "/computer/slack/install") return true;+ return method === "DELETE" && suffix === "/computer/slack";+}++// The backend's codes are stable; the messages are written here so no+// infrastructure detail (cloud, capacity pools, hosts) reaches the dashboard.+export const COMPUTER_ERROR_MESSAGES: Record<string, string> = {+ computer_not_configured:+ "Computers are not available for this organization yet.",+ computer_not_found: "This organization does not have a computer yet.",+ computer_unavailable:+ "Your computer is temporarily unavailable. Try again shortly.",+ computer_capacity_unavailable:+ "We could not set up your computer right now. Try again shortly.",+ computer_busy: "Your computer is changing state. Try again in a moment.",+ computer_slack_not_configured:+ "The OpenComputer Slack app is not available yet.",+ computer_slack_not_installed:+ "No Slack workspace is linked to this organization.",+ computer_slack_already_linked:+ "That Slack workspace is already linked to another organization.",+};++/** Fallback copy for a computer route when the backend's code is unknown. */+export function computerFallbackMessage(status: number): string {+ if (status === 401 || status === 403) {+ return "You do not have access to this organization's computer.";+ }+ if (status === 404) return "This organization does not have a computer yet.";+ if (status === 409) {+ return "Your computer is changing state. Try again in a moment.";+ }+ if (status === 429) return "Too many requests. Try again shortly.";+ if (status >= 500) {+ return "Your computer is temporarily unavailable. Try again shortly.";+ }+ return "The computer request could not be completed.";+}++function record(value: unknown): Record<string, unknown> | null {+ return value && typeof value === "object" && !Array.isArray(value)+ ? (value as Record<string, unknown>)+ : null;+}++function optionalString(value: unknown): string | null {+ return typeof value === "string" ? value : null;+}++function publicComputer(value: unknown): Record<string, unknown> | null {+ const computer = record(value);+ if (!computer) return null;+ return {+ state: computer.state,+ connected: computer.connected === true,+ vcpus: computer.vcpus,+ memoryGiB: computer.memoryGiB,+ diskGiB: computer.diskGiB,+ lastError: optionalString(computer.lastError),+ createdAt: computer.createdAt,+ updatedAt: computer.updatedAt,+ };+}++function publicComputerStatus(body: Record<string, unknown>) {+ const slack = record(body.slack) ?? {};+ const github = record(body.github) ?? {};+ return {+ computer: publicComputer(body.computer),+ slack: {+ installed: slack.installed === true,+ ...(typeof slack.teamId === "string" ? { teamId: slack.teamId } : {}),+ ...(typeof slack.teamName === "string"+ ? { teamName: slack.teamName }+ : {}),+ },+ github: {+ connected: github.connected === true,+ installations: Array.isArray(github.installations)+ ? github.installations.map((value) => {+ const installation = record(value) ?? {};+ return {+ id:+ typeof installation.id === "number"+ ? String(installation.id)+ : installation.id,+ accountLogin: installation.accountLogin,+ };+ })+ : [],+ },+ plan: body.plan === "paid" ? "paid" : "free",+ };+}++function httpsURL(value: unknown): string | null {+ if (typeof value !== "string") return null;+ try {+ const url = new URL(value);+ return url.protocol === "https:" && !url.username && !url.password+ ? url.toString()+ : null;+ } catch {+ return null;+ }+}++function publicComputerSession(value: unknown): Record<string, unknown> {+ const session = record(value) ?? {};+ return {+ key: session.key,+ title: session.title,+ channelId: session.channelId,+ threadTs: session.threadTs,+ ownerSlackUserId: optionalString(session.ownerSlackUserId),+ status: session.status,+ updatedAt: session.updatedAt,+ slackUrl: httpsURL(session.slackUrl),+ };+}++/**+ * The public body for a successful computer route. Throws on a body that+ * cannot honour the contract (the proxy turns that into its generic 502).+ */+export function publicComputerBody(+ method: string,+ suffix: string,+ value: unknown,+): unknown {+ const body = record(value) ?? {};+ if (suffix === "/computer") return publicComputerStatus(body);+ if (method === "GET" && suffix === "/computer/sessions") {+ return {+ sessions: Array.isArray(body.sessions)+ ? body.sessions.map(publicComputerSession)+ : [],+ };+ }+ if (method === "POST" && suffix === "/computer/slack/install") {+ const url = httpsURL(body.url);+ if (!url) throw new Error("Invalid Slack install URL");+ return { url };+ }+ throw new Error("Unsupported computer response");+}diff --git a/cloudflare-workers/api-edge/src/index.test.ts b/cloudflare-workers/api-edge/src/index.test.tsindex f7fb2b01..44ac28d6 100644--- a/cloudflare-workers/api-edge/src/index.test.ts+++ b/cloudflare-workers/api-edge/src/index.test.ts@@ -572,3 +572,70 @@ describe("/api/managed-agents/linear — public mounts", () => {expect(fetchSpy).not.toHaveBeenCalled();});});++describe("/api/managed-agents/computer/slack — public mounts", () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ });++ // The organization-level Slack app calls these URLs without OpenComputer+ // credentials, so they must be routed above the API-key check.+ it("forwards the OAuth redirect without an API key", async () => {+ const location = "https://app.opencomputer.dev/computer?slack=error&reason=state_expired";+ const fetchSpy = vi.fn(+ async (_target: URL | RequestInfo, _init?: RequestInit) =>+ new Response(null, { status: 302, headers: { location } }),+ );+ vi.stubGlobal("fetch", fetchSpy);++ const resp = await worker.fetch(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/computer/slack/callback?state=x&code=y",+ ),+ { ...env, MANAGED_AGENTS_API_URL: "https://managedagents.test" },+ ctx,+ );++ expect(resp.status).toBe(302);+ expect(resp.headers.get("location")).toBe(location);+ expect(fetchSpy.mock.calls[0][0].toString()).toBe(+ "https://managedagents.test/v1/computer/slack/callback?state=x&code=y",+ );+ });++ it.each([+ ["events", "/v1/webhooks/computer/slack/events"],+ ["interactivity", "/v1/webhooks/computer/slack/interactivity"],+ ])("forwards signed Slack %s without an API key", async (kind, upstreamPath) => {+ const fetchSpy = vi.fn(+ async (_target: URL | RequestInfo, _init?: RequestInit) =>+ new Response(null, { status: 200 }),+ );+ vi.stubGlobal("fetch", fetchSpy);++ const resp = await worker.fetch(+ new Request(+ `https://app.opencomputer.dev/api/managed-agents/computer/slack/${kind}`,+ {+ method: "POST",+ headers: {+ "content-type": "application/json",+ "x-slack-signature": "v0=abc",+ "x-slack-request-timestamp": "1700000000",+ },+ body: '{"type":"event_callback"}',+ },+ ),+ { ...env, MANAGED_AGENTS_API_URL: "https://managedagents.test" },+ ctx,+ );++ expect(resp.status).toBe(200);+ expect(fetchSpy).toHaveBeenCalledTimes(1);+ expect(fetchSpy.mock.calls[0][0].toString()).toBe(+ `https://managedagents.test${upstreamPath}`,+ );+ const headers = new Headers(fetchSpy.mock.calls[0][1]?.headers);+ expect(headers.get("x-slack-signature")).toBe("v0=abc");+ });+});diff --git a/cloudflare-workers/api-edge/src/index.ts b/cloudflare-workers/api-edge/src/index.tsindex 3b8a9c0a..47697bf4 100644--- a/cloudflare-workers/api-edge/src/index.ts+++ b/cloudflare-workers/api-edge/src/index.ts@@ -92,6 +92,8 @@ import {handleManagedGitHubWebhook,handleManagedSlackCallback,handleManagedLinearCallback,+ handleComputerSlackCallback,+ handleComputerSlackWebhook,handleManagedAgentChannelConnection,proxyManagedAgents,} from "./managed_agents";@@ -5616,6 +5618,28 @@ export default {) {return handleManagedLinearCallback(req, env);}+ // The organization-level OpenComputer Slack app (work 052). These exact+ // URLs are configured on the app; Slack calls them without OpenComputer+ // credentials, so they stay above the API-key check. The backend verifies+ // Slack's signature over the untouched body.+ if (+ path === "/api/managed-agents/computer/slack/callback" &&+ req.method === "GET"+ ) {+ return handleComputerSlackCallback(req, env);+ }+ if (+ path === "/api/managed-agents/computer/slack/events" &&+ req.method === "POST"+ ) {+ return handleComputerSlackWebhook(req, env, "events");+ }+ if (+ path === "/api/managed-agents/computer/slack/interactivity" &&+ req.method === "POST"+ ) {+ return handleComputerSlackWebhook(req, env, "interactivity");+ }if (path.startsWith("/api/agent-webhooks/")) {return handleAgentWebhookInvocation(req, env);}diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex d385a427..76be00dd 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -2,6 +2,8 @@ import { afterEach, describe, expect, it, vi } from "vitest";import {handleAgentWebhookInvocation,+ handleComputerSlackCallback,+ handleComputerSlackWebhook,handleManagedAgentChannelConnection,handleManagedGitHubCallback,handleManagedLinearCallback,@@ -6444,3 +6446,318 @@ describe("Linear agent connections", () => {expect(fetchMock).not.toHaveBeenCalled();});});++describe("organization computer (work 052)", () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ });++ const env = {+ MANAGED_AGENTS_API_URL: "https://managedagents.test",+ OC_MANAGED_AGENTS_SECRET: "test-secret",+ };+ const caller = { orgID: "org_test", userID: "user_test", role: "admin" };+ const dashboard = "/api/dashboard/managed-agents";++ const computerStatus = {+ computer: {+ state: "ready",+ connected: true,+ vcpus: 2,+ memoryGiB: 8,+ diskGiB: 128,+ lastError: null,+ createdAt: "2026-10-11T10:00:00.000Z",+ updatedAt: "2026-10-11T10:05:00.000Z",+ },+ slack: { installed: true, teamId: "T123", teamName: "Acme" },+ github: {+ connected: true,+ installations: [{ id: "42", accountLogin: "acme" }],+ },+ plan: "free",+ };++ async function call(+ method: string,+ path: string,+ upstream: Response,+ prefix = dashboard,+ ) {+ const fetchMock = vi.fn().mockResolvedValue(upstream);+ vi.stubGlobal("fetch", fetchMock);+ const response = await proxyManagedAgents(+ new Request(`https://app.opencomputer.dev${prefix}${path}`, { method }),+ env,+ caller,+ prefix,+ );+ return { response, fetchMock };+ }++ it.each([+ ["GET", "/computer"],+ ["POST", "/computer"],+ ])("passes the contract body of %s /computer through unchanged", async (method) => {+ const { response, fetchMock } = await call(+ method,+ "/computer",+ Response.json({+ ...computerStatus,+ computer: {+ ...computerStatus.computer,+ vmSize: "private-size",+ region: "private-region",+ hostId: "private-host",+ },+ accountId: "acct_private",+ }),+ );++ expect(response.status).toBe(200);+ expect(response.headers.get("cache-control")).toBe("no-store");+ await expect(response.json()).resolves.toEqual(computerStatus);+ const [target, init] = fetchMock.mock.calls[0] as [URL, RequestInit];+ expect(target.toString()).toBe("https://managedagents.test/v1/computer");+ expect(init.method).toBe(method);+ expect(+ new Headers(init.headers).get("x-opencomputer-agent-token"),+ ).toBeTruthy();+ });++ it("passes a missing computer and an unlinked Slack through", async () => {+ const body = {+ computer: null,+ slack: { installed: false },+ github: { connected: false, installations: [] },+ plan: "free",+ };+ const { response } = await call("GET", "/computer", Response.json(body));+ await expect(response.json()).resolves.toEqual(body);+ });++ it("lists computer sessions with their Slack links", async () => {+ const session = {+ key: "C1:1700000000.000100",+ title: "Fix the flaky test",+ channelId: "C1",+ threadTs: "1700000000.000100",+ ownerSlackUserId: "U1",+ status: "busy",+ updatedAt: "2026-10-11T10:05:00.000Z",+ slackUrl: "https://acme.slack.com/archives/C1/p1700000000000100",+ };+ const { response, fetchMock } = await call(+ "GET",+ "/computer/sessions",+ Response.json({+ sessions: [+ { ...session, runnerPid: 4242 },+ { ...session, key: "k2", ownerSlackUserId: null, slackUrl: "javascript:alert(1)" },+ ],+ }),+ );+ await expect(response.json()).resolves.toEqual({+ sessions: [+ session,+ { ...session, key: "k2", ownerSlackUserId: null, slackUrl: null },+ ],+ });+ expect(fetchMock.mock.calls[0]?.[0].toString()).toBe(+ "https://managedagents.test/v1/computer/sessions",+ );+ });++ it("returns the Slack authorize URL for the install", async () => {+ const url =+ "https://slack.com/oauth/v2/authorize?client_id=1.2&scope=chat%3Awrite&state=opaque";+ const { response } = await call(+ "POST",+ "/computer/slack/install",+ Response.json({ url }),+ );+ await expect(response.json()).resolves.toEqual({ url });+ });++ it("answers an unlink with no content", async () => {+ const { response, fetchMock } = await call(+ "DELETE",+ "/computer/slack",+ Response.json({ ok: true }),+ );+ expect(response.status).toBe(204);+ const [target, init] = fetchMock.mock.calls[0] as [URL, RequestInit];+ expect(target.toString()).toBe(+ "https://managedagents.test/v1/computer/slack",+ );+ expect(init.method).toBe("DELETE");+ });++ it.each([+ ["PUT", "/computer"],+ ["DELETE", "/computer"],+ ["GET", "/computer/host"],+ ["GET", "/computer/slack/callback"],+ ["POST", "/computer/sessions"],+ ])("refuses %s %s outside the contract", async (method, path) => {+ const { response, fetchMock } = await call(+ method,+ path,+ Response.json({}),+ );+ expect(response.status).toBe(404);+ expect(fetchMock).not.toHaveBeenCalled();+ });++ it("keeps the computer off the API-key mount", async () => {+ const { response, fetchMock } = await call(+ "GET",+ "/computer",+ Response.json(computerStatus),+ "/api/managed-agents",+ );+ expect(response.status).toBe(404);+ expect(fetchMock).not.toHaveBeenCalled();+ });++ it("maps a known backend code to fixed copy", async () => {+ const { response } = await call(+ "POST",+ "/computer",+ Response.json(+ {+ error: {+ code: "computer_not_configured",+ message: "AZURE_CLIENT_SECRET missing in eastus",+ },+ },+ { status: 503 },+ ),+ );+ expect(response.status).toBe(503);+ await expect(response.json()).resolves.toEqual({+ error: {+ code: "computer_not_configured",+ message: "Computers are not available for this organization yet.",+ },+ });+ });++ it("never passes an unknown backend message through", async () => {+ const { response } = await call(+ "GET",+ "/computer",+ Response.json(+ { error: { code: "allocation_failed", message: "Standard_D2as_v7 in eastus" } },+ { status: 500 },+ ),+ );+ const body = (await response.json()) as { error: { message: string } };+ expect(body.error.message).toBe(+ "Your computer is temporarily unavailable. Try again shortly.",+ );+ });++ it("forwards the Slack OAuth redirect to the computer callback", async () => {+ const location = "https://app.opencomputer.dev/computer?slack=connected";+ const fetchMock = vi+ .fn()+ .mockResolvedValue(+ new Response(null, { status: 302, headers: { location } }),+ );+ vi.stubGlobal("fetch", fetchMock);++ const response = await handleComputerSlackCallback(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/computer/slack/callback?code=c&state=s",+ ),+ { MANAGED_AGENTS_API_URL: "https://managedagents.test" },+ );++ expect(response.status).toBe(302);+ expect(response.headers.get("location")).toBe(location);+ expect(fetchMock.mock.calls[0]?.[0].toString()).toBe(+ "https://managedagents.test/v1/computer/slack/callback?code=c&state=s",+ );+ });++ it.each([+ [+ "events" as const,+ "application/json",+ '{"type":"url_verification","challenge":"abc"}',+ "/v1/webhooks/computer/slack/events",+ ],+ [+ "interactivity" as const,+ "application/x-www-form-urlencoded",+ "payload=%7B%22type%22%3A%22block_actions%22%7D",+ "/v1/webhooks/computer/slack/interactivity",+ ],+ ])(+ "forwards Slack %s byte for byte with its signature",+ async (kind, contentType, body, upstreamPath) => {+ const fetchMock = vi.fn(+ async (_target: URL | RequestInfo, _init?: RequestInit) =>+ new Response('{"challenge":"abc"}', {+ status: 200,+ headers: { "content-type": "application/json", "set-cookie": "x=1" },+ }),+ );+ vi.stubGlobal("fetch", fetchMock);++ const response = await handleComputerSlackWebhook(+ new Request(+ `https://app.opencomputer.dev/api/managed-agents/computer/slack/${kind}`,+ {+ method: "POST",+ headers: {+ "content-type": contentType,+ "x-slack-signature": "v0=deadbeef",+ "x-slack-request-timestamp": "1700000000",+ "x-slack-retry-num": "1",+ "x-slack-retry-reason": "http_timeout",+ cookie: "oc_session=private",+ authorization: "Bearer private",+ },+ body,+ },+ ),+ { MANAGED_AGENTS_API_URL: "https://managedagents.test" },+ kind,+ );++ expect(response.status).toBe(200);+ await expect(response.text()).resolves.toBe('{"challenge":"abc"}');+ expect(response.headers.get("set-cookie")).toBeNull();+ const [target, init] = fetchMock.mock.calls[0] as [URL, RequestInit];+ expect(target.toString()).toBe(`https://managedagents.test${upstreamPath}`);+ expect(init.method).toBe("POST");+ expect(new TextDecoder().decode(init.body as ArrayBuffer)).toBe(body);+ const headers = new Headers(init.headers);+ expect(headers.get("content-type")).toBe(contentType);+ expect(headers.get("x-slack-signature")).toBe("v0=deadbeef");+ expect(headers.get("x-slack-request-timestamp")).toBe("1700000000");+ expect(headers.get("x-slack-retry-num")).toBe("1");+ expect(headers.get("x-slack-retry-reason")).toBe("http_timeout");+ expect(headers.get("cookie")).toBeNull();+ expect(headers.get("authorization")).toBeNull();+ expect(headers.get("x-opencomputer-agent-token")).toBeNull();+ },+ );++ it("refuses to forward Slack events over plain HTTP", async () => {+ const fetchMock = vi.fn();+ vi.stubGlobal("fetch", fetchMock);+ const response = await handleComputerSlackWebhook(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/computer/slack/events",+ { method: "POST", body: "{}" },+ ),+ { MANAGED_AGENTS_API_URL: "http://managedagents.test" },+ "events",+ );+ expect(response.status).toBe(503);+ expect(fetchMock).not.toHaveBeenCalled();+ });+});diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex 4cc4096b..28202ea8 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -1,4 +1,11 @@import { getAutumnCustomer } from "./autumn_webhook";+import {+ COMPUTER_ERROR_MESSAGES,+ computerFallbackMessage,+ isComputerRoute,+ isComputerRouteSuffix,+ publicComputerBody,+} from "./computer";export interface ManagedAgentsEnv {MANAGED_AGENTS_API_URL?: string;@@ -15,6 +22,7 @@ export interface ManagedAgentsCaller {}const DEFAULT_MANAGED_AGENTS_API_URL = "https://managedagents.opencomputer.dev";+const DASHBOARD_MANAGED_AGENTS_PREFIX = "/api/dashboard/managed-agents";const MAX_AGENT_SOURCE_BYTES = 10 * 1024 * 1024;export async function hasBYOKPlanAccess(@@ -277,7 +285,15 @@ async function publicErrorResponse(Object.hasOwn(LINEAR_ROUTE_ERROR_MESSAGES, backendCode)? LINEAR_ROUTE_ERROR_MESSAGES[backendCode]: undefined;- if (slackSetupMessage) {+ const computerMessage =+ suffix !== undefined && isComputerRouteSuffix(suffix)+ ? Object.hasOwn(COMPUTER_ERROR_MESSAGES, backendCode)+ ? COMPUTER_ERROR_MESSAGES[backendCode]+ : computerFallbackMessage(upstream.status)+ : undefined;+ if (computerMessage) {+ message = computerMessage;+ } else if (slackSetupMessage) {message = slackSetupMessage;} else if (deploymentSourceMessage) {message = deploymentSourceMessage;@@ -2617,6 +2633,8 @@ async function deploySourceAgent(}function isAllowedManagedAgentsRoute(method: string, suffix: string): boolean {+ // The organization's computer: only the contract's routes (work 052).+ if (isComputerRouteSuffix(suffix)) return isComputerRoute(method, suffix);if (method === "GET" && suffix === "/account/runtime-profile") return true;if (method === "POST" && suffix === "/template-inspections") return true;if (method === "POST" && suffix === "/template-installations") return true;@@ -3035,6 +3053,88 @@ export async function handleManagedLinearCallback();}+/**+ * Slack's OAuth redirect for the organization-level OpenComputer Slack app+ * (work 052). The backend binds the workspace to the organization named by+ * its single-use state and redirects to `/computer?slack=connected` or+ * `/computer?slack=error&reason=<code>`; the redirect passes through as is.+ */+export async function handleComputerSlackCallback(+ request: Request,+ env: ManagedAgentsEnv,+): Promise<Response> {+ return forwardProviderCallback(+ request,+ env,+ "/v1/computer/slack/callback",+ "Slack",+ );+}++const COMPUTER_SLACK_WEBHOOK_PATHS = {+ events: "/v1/webhooks/computer/slack/events",+ interactivity: "/v1/webhooks/computer/slack/interactivity",+} as const;++/**+ * Slack Events API and interactivity deliveries for the organization-level+ * Slack app. Slack signs the exact body bytes with the request timestamp, and+ * the backend verifies that signature, so the body is forwarded byte for byte+ * with Slack's signature, timestamp and retry headers and nothing is trusted+ * here. The backend's answer (a URL verification challenge, an interactivity+ * response action, or an empty acknowledgement) goes back to Slack unchanged.+ */+export async function handleComputerSlackWebhook(+ request: Request,+ env: ManagedAgentsEnv,+ kind: keyof typeof COMPUTER_SLACK_WEBHOOK_PATHS,+): Promise<Response> {+ if (request.method !== "POST") {+ return new Response("Method not allowed", { status: 405 });+ }+ const base = (+ env.MANAGED_AGENTS_API_URL ?? DEFAULT_MANAGED_AGENTS_API_URL+ ).replace(/\/+$/, "");+ const target = new URL(`${base}${COMPUTER_SLACK_WEBHOOK_PATHS[kind]}`);+ if (target.protocol !== "https:" && target.hostname !== "localhost") {+ return new Response("Slack events are unavailable", { status: 503 });+ }+ const headers = new Headers();+ for (const name of [+ "content-type",+ "x-slack-signature",+ "x-slack-request-timestamp",+ "x-slack-retry-num",+ "x-slack-retry-reason",+ ]) {+ const value = request.headers.get(name);+ if (value) headers.set(name, value);+ }+ try {+ const upstream = await fetch(target, {+ method: "POST",+ headers,+ body: await request.arrayBuffer(),+ redirect: "manual",+ });+ const responseHeaders = new Headers({ "cache-control": "no-store" });+ const contentType = upstream.headers.get("content-type");+ if (contentType) responseHeaders.set("content-type", contentType);+ return new Response(upstream.body, {+ status: upstream.status,+ headers: responseHeaders,+ });+ } catch {+ return new Response(+ JSON.stringify({ error: { code: "slack_events_unavailable" } }),+ {+ status: 502,+ headers: { "content-type": "application/json" },+ },+ );+ }+}+function channelConnectionPage(action: string,status: number,@@ -3384,6 +3484,13 @@ export async function proxyManagedAgents(if (!isAllowedManagedAgentsRoute(request.method.toUpperCase(), suffix)) {return Response.json({ error: "route not found" }, { status: 404 });}+ // The computer is a dashboard surface in v1; API keys do not reach it.+ if (+ isComputerRouteSuffix(suffix) &&+ publicPrefix !== DASHBOARD_MANAGED_AGENTS_PREFIX+ ) {+ return Response.json({ error: "route not found" }, { status: 404 });+ }if (!env.OC_MANAGED_AGENTS_SECRET) {return Response.json({ error: "managed agents are not configured" },@@ -3577,6 +3684,19 @@ export async function proxyManagedAgents(}if (!upstream.ok) return publicErrorResponse(upstream, suffix);if (upstream.status === 204) return new Response(null, { status: 204 });+ if (isComputerRouteSuffix(suffix)) {+ // Unlinking Slack has no response body in the contract.+ if (method === "DELETE") {+ return new Response(null, {+ status: 204,+ headers: { "cache-control": "no-store" },+ });+ }+ return Response.json(+ publicComputerBody(method, suffix, await upstream.json()),+ { status: upstream.status, headers: { "cache-control": "no-store" } },+ );+ }if (/^\/projects\/[^/]+\/source-archive$/.test(suffix) ||WORKSPACE_ARTIFACT_CONTENT_ROUTE.test(suffix)