Skip to content

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

feat: snapshot

mogeryc54c3f7a6552
diff --git a/apps/api/src/controllers/v2/agent-snapshot.ts b/apps/api/src/controllers/v2/agent-snapshot.ts
new file mode 100644
index 000000000..08cb130e7
--- /dev/null
+++ b/apps/api/src/controllers/v2/agent-snapshot.ts
@@ -0,0 +1,40 @@
+import { Response } from "express";
+import { config } from "../../config";
+import { supabaseGetAgentRequestByIdDirect } from "../../lib/supabase-jobs";
+import { AgentSnapshotResponse, RequestWithAuth } from "./types";
+
+export async function agentSnapshotController(
+ req: RequestWithAuth<
+ { jobId: string; snapshotId: string },
+ AgentSnapshotResponse,
+ any
+ >,
+ res: Response<AgentSnapshotResponse>,
+) {
+ const agentRequest = await supabaseGetAgentRequestByIdDirect(
+ req.params.jobId,
+ );
+
+ if (!agentRequest || agentRequest.team_id !== req.auth.team_id) {
+ return res.status(404).json({
+ success: false,
+ error: "Agent job not found",
+ });
+ }
+
+ if (!config.EXTRACT_V3_BETA_URL) {
+ throw new Error("Agent beta is not enabled.");
+ }
+
+ const upstream = await fetch(
+ `${config.EXTRACT_V3_BETA_URL}/internal/extracts/${req.params.jobId}/snapshots/${req.params.snapshotId}`,
+ {
+ headers: {
+ Authorization: `Bearer ${config.AGENT_INTEROP_SECRET}`,
+ },
+ },
+ );
+ const body = (await upstream.json()) as AgentSnapshotResponse;
+
+ return res.status(upstream.status).json(body);
+}
diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.ts
index 0b7c6deac..9296c2136 100644
--- a/apps/api/src/controllers/v2/types.ts
+++ b/apps/api/src/controllers/v2/types.ts
@@ -1454,6 +1454,15 @@ export type AgentTraceResponse =
creditsUsed: number;
};
+export type AgentSnapshotResponse =
+ | ErrorResponse
+ | {
+ success: true;
+ id: string;
+ snapshotId: string;
+ snapshot: string;
+ };
+
export type AgentCancelResponse =
| ErrorResponse
| {
diff --git a/apps/api/src/routes/v2.ts b/apps/api/src/routes/v2.ts
index 2eb28bdef..b64c25621 100644
--- a/apps/api/src/routes/v2.ts
+++ b/apps/api/src/routes/v2.ts
@@ -55,6 +55,7 @@ import { agentController } from "../controllers/v2/agent";
import { agentStatusController } from "../controllers/v2/agent-status";
import { agentCancelController } from "../controllers/v2/agent-cancel";
import { agentTraceController } from "../controllers/v2/agent-trace";
+import { agentSnapshotController } from "../controllers/v2/agent-snapshot";
import {
browserCreateController,
browserExecuteController,
@@ -397,6 +398,13 @@ v2Router.get(
wrap(agentTraceController),
);
+v2Router.get(
+ "/agent/:jobId/snapshots/:snapshotId",
+ authMiddleware(RateLimiterMode.ExtractStatus),
+ validateJobIdParam,
+ wrap(agentSnapshotController),
+);
+
v2Router.delete(
"/agent/:jobId",
authMiddleware(RateLimiterMode.ExtractStatus),