Skip to content

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

feat(api): read activity and agent listings from the Pub/Sub-fed tables (#4682)

Gergő Móricz4a44406670c2
diff --git a/apps/api/src/controllers/v1/__tests__/activity.test.ts b/apps/api/src/controllers/v1/__tests__/activity.test.ts
index 485d2924d..d0b9b8ac4 100644
--- a/apps/api/src/controllers/v1/__tests__/activity.test.ts
+++ b/apps/api/src/controllers/v1/__tests__/activity.test.ts
@@ -80,7 +80,10 @@ describe("activityController", () => {
});
const cursorRes = makeRes();
- await activityController(makeReq({ cursor: "bm8tc2VwYXJhdG9y" }), cursorRes);
+ await activityController(
+ makeReq({ cursor: "bm8tc2VwYXJhdG9y" }),
+ cursorRes,
+ );
expect(cursorRes.status).toHaveBeenCalledWith(400);
expect(cursorRes.json).toHaveBeenCalledWith({
@@ -90,7 +93,7 @@ describe("activityController", () => {
expect(mocks.query).not.toHaveBeenCalled();
});
- it("queries public_requests for the authenticated team and 24-hour window", async () => {
+ it("queries requests for the authenticated team and 24-hour window", async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-09-16T12:34:56.789Z"));
mockRows([]);
@@ -100,7 +103,7 @@ describe("activityController", () => {
expect(mocks.query).toHaveBeenCalledOnce();
const options = mocks.query.mock.calls[0][0];
- expect(options.query).toContain("FROM public_requests");
+ expect(options.query).toContain("FROM requests");
expect(options.query).toContain("team_id = {teamId: UUID}");
expect(options.query).toContain(
"created_at >= {windowStart: DateTime64(3)}",
@@ -217,10 +220,9 @@ describe("activityController", () => {
await activityController(makeReq(), res);
- expect(mocks.loggerError).toHaveBeenCalledWith(
- "Failed to fetch activity",
- { error },
- );
+ expect(mocks.loggerError).toHaveBeenCalledWith("Failed to fetch activity", {
+ error,
+ });
expect(res.status).toHaveBeenCalledWith(500);
expect(res.json).toHaveBeenCalledWith({
success: false,
diff --git a/apps/api/src/controllers/v1/activity.ts b/apps/api/src/controllers/v1/activity.ts
index 7c0d69d4d..82d763c51 100644
--- a/apps/api/src/controllers/v1/activity.ts
+++ b/apps/api/src/controllers/v1/activity.ts
@@ -113,9 +113,7 @@ export async function activityController(
}
const windowStart = toClickHouseDateTime(
- new Date(
- Date.now() - ACTIVITY_WINDOW_HOURS * 60 * 60 * 1000,
- ).toISOString(),
+ new Date(Date.now() - ACTIVITY_WINDOW_HOURS * 60 * 60 * 1000).toISOString(),
);
const conditions = [
@@ -146,7 +144,7 @@ export async function activityController(
const result = await clickhouseClient.query({
query: `
SELECT id, kind, api_version, created_at, target_hint
- FROM public_requests
+ FROM requests
WHERE ${conditions.join(" AND ")}
ORDER BY created_at DESC, id DESC
LIMIT {limit: UInt32}
diff --git a/apps/api/src/controllers/v2/agent-list.ts b/apps/api/src/controllers/v2/agent-list.ts
index 0c8ba8fdf..7bf3206e2 100644
--- a/apps/api/src/controllers/v2/agent-list.ts
+++ b/apps/api/src/controllers/v2/agent-list.ts
@@ -93,7 +93,7 @@ export async function agentListController(
(async () => {
const requestsRes = await clickhouseClient.query({
query:
- "SELECT id, created_at, target_hint, origin, integration FROM public_requests WHERE team_id = {teamId: UUID} AND kind = 'agent' AND created_at < {before: DateTime} ORDER BY created_at DESC LIMIT {limit: UInt32};",
+ "SELECT id, created_at, target_hint, origin, integration FROM requests WHERE team_id = {teamId: UUID} AND kind = 'agent' AND created_at < {before: DateTime} ORDER BY created_at DESC LIMIT {limit: UInt32};",
query_params: {
teamId: req.auth.team_id,
// Fetch one extra row so we can tell whether another page exists
@@ -129,10 +129,13 @@ export async function agentListController(
}),
);
+ // `agents` is keyed by (team_id, id); the team filter keeps this a
+ // primary-key read instead of a scan.
const agentsRes = await clickhouseClient.query({
query:
- "SELECT id, options, is_successful FROM public_agents WHERE id IN {ids: Array(UUID)};",
+ "SELECT id, options, is_successful, error FROM agents WHERE team_id = {teamId: UUID} AND id IN {ids: Array(UUID)};",
query_params: {
+ teamId: req.auth.team_id,
ids: bareRequests.map(x => x.id),
},
format: "JSONEachRow",