Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): restore the five labs routes dropped by the rate limit change (#4249)

Nicolas1313ddb495ef
diff --git a/apps/api/src/__tests__/routes/labs.routes.test.ts b/apps/api/src/__tests__/routes/labs.routes.test.ts
new file mode 100644
index 000000000..d682a3242
--- /dev/null
+++ b/apps/api/src/__tests__/routes/labs.routes.test.ts
@@ -0,0 +1,98 @@
+import express from "express";
+import request from "supertest";
+
+vi.mock("../../config", () => ({
+ config: {
+ LABS_SEARCH_URL: "https://labs.test",
+ LABS_SEARCH_SECRET: "test-secret",
+ },
+}));
+
+vi.mock("../../lib/logger", () => {
+ const logger = {
+ child: () => logger,
+ error: vi.fn(),
+ warn: vi.fn(),
+ info: vi.fn(),
+ debug: vi.fn(),
+ };
+ return { logger };
+});
+
+vi.mock("../../routes/shared", () => ({
+ authMiddleware: () => (_req: any, _res: any, next: any) => next(),
+ wrap: (fn: any) => fn,
+}));
+
+import { labsRouter } from "../../routes/labs";
+
+const LABS_ROUTES = [
+ "POST /search",
+ "POST /search/data/sites",
+ "POST /search/data/documents",
+ "POST /search/data/pages",
+ "GET /search/data",
+ "PATCH /search/data/:sourceId",
+ "DELETE /search/data/:sourceId",
+ "POST /search/data/:sourceId/refresh",
+ "GET /search/providers",
+ "GET /search/packs",
+ "PATCH /search/packs/:packId",
+ "POST /search/configs",
+ "GET /search/configs",
+ "PATCH /search/configs/:id",
+ "DELETE /search/configs/:id",
+];
+
+function registeredRoutes(): string[] {
+ return labsRouter.stack.flatMap(layer => {
+ const route = layer.route;
+ if (route === undefined || typeof route.path !== "string") return [];
+ const path = route.path;
+ const methods = new Set(route.stack.map(entry => entry.method));
+ return [...methods].map(method => `${method.toUpperCase()} ${path}`);
+ });
+}
+
+function appWithLabs() {
+ const app = express();
+ app.use("/labs", labsRouter);
+ return app;
+}
+
+describe("labs router", () => {
+ it("proxies every route the Labs Search service serves", () => {
+ expect(registeredRoutes().sort()).toEqual([...LABS_ROUTES].sort());
+ });
+
+ it("keeps the provider pack routes the dashboard reads", () => {
+ expect(registeredRoutes()).toContain("GET /search/packs");
+ expect(registeredRoutes()).toContain("PATCH /search/packs/:packId");
+ });
+
+ it("answers an unproxied labs path with JSON naming the gap", async () => {
+ const response = await request(appWithLabs()).get(
+ "/labs/search/not-a-route",
+ );
+
+ expect(response.status).toBe(404);
+ expect(response.type).toBe("application/json");
+ expect(response.body.code).toBe("LABS_ROUTE_NOT_PROXIED");
+ expect(response.body.error).toContain("/labs/search/not-a-route");
+ expect(response.body.error).toContain("does not forward it yet");
+ });
+
+ it("names the method so a wrong-verb route is not read as a missing record", async () => {
+ const response = await request(appWithLabs()).put("/labs/search/configs");
+
+ expect(response.status).toBe(404);
+ expect(response.body.code).toBe("LABS_ROUTE_NOT_PROXIED");
+ expect(response.body.error).toContain("PUT /labs/search/configs");
+ });
+
+ it("lets proxied routes through rather than swallowing them in the catch-all", async () => {
+ const response = await request(appWithLabs()).get("/labs/search/packs");
+
+ expect(response.body.code).not.toBe("LABS_ROUTE_NOT_PROXIED");
+ });
+});
diff --git a/apps/api/src/routes/labs.ts b/apps/api/src/routes/labs.ts
index 050c3660e..aa62f6746 100644
--- a/apps/api/src/routes/labs.ts
+++ b/apps/api/src/routes/labs.ts
@@ -58,8 +58,6 @@ function upstreamHeaders(req: RequestWithAuth<any, any, any>) {
if (apiKey) headers["x-labs-search-key"] = apiKey;
if (isMultipart(req)) {
- // The body is piped through unparsed, so the multipart boundary and length
- // have to travel with it.
for (const h of ["content-type", "content-length"]) {
const value = req.headers[h];
if (typeof value === "string") headers[h] = value;
@@ -136,9 +134,6 @@ async function labsProxyController(req: Request, res: Response) {
export const labsRouter = express.Router();
-// No credit check or billing here on purpose: the service behind this proxy
-// makes its own calls to the public API with the caller's own key, so usage is
-// billed on those existing paths instead.
labsRouter.post(
"/search",
authMiddleware(RateLimiterMode.Labs),
@@ -157,24 +152,54 @@ labsRouter.post(
wrap(labsProxyController),
);
+labsRouter.post(
+ "/search/data/pages",
+ authMiddleware(RateLimiterMode.Labs),
+ wrap(labsProxyController),
+);
+
labsRouter.get(
"/search/data",
authMiddleware(RateLimiterMode.Labs),
wrap(labsProxyController),
);
+labsRouter.patch(
+ "/search/data/:sourceId",
+ authMiddleware(RateLimiterMode.Labs),
+ wrap(labsProxyController),
+);
+
labsRouter.delete(
"/search/data/:sourceId",
authMiddleware(RateLimiterMode.Labs),
wrap(labsProxyController),
);
+labsRouter.post(
+ "/search/data/:sourceId/refresh",
+ authMiddleware(RateLimiterMode.Labs),
+ wrap(labsProxyController),
+);
+
labsRouter.get(
"/search/providers",
authMiddleware(RateLimiterMode.Labs),
wrap(labsProxyController),
);
+labsRouter.get(
+ "/search/packs",
+ authMiddleware(RateLimiterMode.Labs),
+ wrap(labsProxyController),
+);
+
+labsRouter.patch(
+ "/search/packs/:packId",
+ authMiddleware(RateLimiterMode.Labs),
+ wrap(labsProxyController),
+);
+
labsRouter.post(
"/search/configs",
authMiddleware(RateLimiterMode.Labs),
@@ -198,3 +223,18 @@ labsRouter.delete(
authMiddleware(RateLimiterMode.Labs),
wrap(labsProxyController),
);
+
+labsRouter.all(/(.*)/, (req: Request, res: Response) => {
+ rootLogger.warn("Labs path is not proxied by this API", {
+ module: "api/labs",
+ method: req.method,
+ path: req.originalUrl,
+ });
+ return res.status(404).json({
+ success: false,
+ code: "LABS_ROUTE_NOT_PROXIED",
+ error:
+ `${req.method} ${req.baseUrl}${req.path} is not routed by this API. The Labs Search ` +
+ `service may serve it, but this proxy does not forward it yet.`,
+ });
+});