Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat(api): ab/c
Gergő Móricz0a5cc475ff8f
diff --git a/apps/api/src/controllers/v2/agent-cancel.ts b/apps/api/src/controllers/v2/agent-cancel.tsnew file mode 100644index 000000000..d1edcc489--- /dev/null+++ b/apps/api/src/controllers/v2/agent-cancel.ts@@ -0,0 +1,49 @@+import { Response } from "express";+import { AgentCancelResponse, RequestWithAuth } from "./types";+import {+ supabaseGetAgentByIdDirect,+ supabaseGetAgentRequestByIdDirect,+} from "../../lib/supabase-jobs";+import { config } from "../../config";++export async function agentCancelController(+ req: RequestWithAuth<{ jobId: string }, AgentCancelResponse, any>,+ res: Response<AgentCancelResponse>,+) {+ 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",+ });+ }++ const agent = await supabaseGetAgentByIdDirect(req.params.jobId);+ if (agent) {+ return res.status(409).json({+ success: false,+ error: "Agent already finished",+ });+ }++ const resp = await fetch(+ config.EXTRACT_V3_BETA_URL + "/internal/extracts/" + req.params.jobId,+ {+ method: "DELETE",+ },+ );++ if (resp.status === 409) {+ return res.status(409).json({+ success: false,+ error: "Agent is already cancelled",+ });+ }++ return res.status(200).json({+ success: true,+ });+}diff --git a/apps/api/src/controllers/v2/agent-status.ts b/apps/api/src/controllers/v2/agent-status.tsindex d112bbfa3..a2c99ce5f 100644--- a/apps/api/src/controllers/v2/agent-status.ts+++ b/apps/api/src/controllers/v2/agent-status.ts@@ -18,7 +18,7 @@ export async function agentStatusController(if (!agentRequest || agentRequest.team_id !== req.auth.team_id) {return res.status(404).json({success: false,- error: "Extract job not found",+ error: "Agent job not found",});}diff --git a/apps/api/src/controllers/v2/agent.ts b/apps/api/src/controllers/v2/agent.tsindex 521e1031d..3204d9314 100644--- a/apps/api/src/controllers/v2/agent.ts+++ b/apps/api/src/controllers/v2/agent.ts@@ -17,6 +17,7 @@ export async function agentController(const agentId = uuidv7();const logger = _logger.child({agentId,+ extractId: agentId,jobId: agentId,teamId: req.auth.team_id,team_id: req.auth.team_id,diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.tsindex d9701d028..28a3bd2d5 100644--- a/apps/api/src/controllers/v2/types.ts+++ b/apps/api/src/controllers/v2/types.ts@@ -1091,6 +1091,12 @@ export type AgentStatusResponse =creditsUsed?: number;};+export type AgentCancelResponse =+ | ErrorResponse+ | {+ success: boolean;+ };+export type CrawlResponse =| ErrorResponse| {diff --git a/apps/api/src/routes/v2.ts b/apps/api/src/routes/v2.tsindex 4325596aa..82a4da0b1 100644--- a/apps/api/src/routes/v2.ts+++ b/apps/api/src/routes/v2.ts@@ -38,6 +38,7 @@ import { paymentMiddleware } from "x402-express";import { facilitator } from "@coinbase/x402";import { agentController } from "../controllers/v2/agent";import { agentStatusController } from "../controllers/v2/agent-status";+import { agentCancelController } from "../controllers/v2/agent-cancel";expressWs(express());@@ -317,6 +318,13 @@ v2Router.get(wrap(agentStatusController),);+v2Router.delete(+ "/agent/:jobId",+ authMiddleware(RateLimiterMode.ExtractStatus),+ validateJobIdParam,+ wrap(agentCancelController),+);+v2Router.get("/team/credit-usage",authMiddleware(RateLimiterMode.CrawlStatus),diff --git a/apps/js-sdk/firecrawl/package.json b/apps/js-sdk/firecrawl/package.jsonindex 7e2b049de..708ed29aa 100644--- a/apps/js-sdk/firecrawl/package.json+++ b/apps/js-sdk/firecrawl/package.json@@ -1,6 +1,6 @@{"name": "@mendable/firecrawl-js",- "version": "4.9.0",+ "version": "4.9.1","description": "JavaScript SDK for Firecrawl API","main": "dist/index.js","types": "dist/index.d.ts",diff --git a/apps/js-sdk/firecrawl/src/v2/client.ts b/apps/js-sdk/firecrawl/src/v2/client.tsindex d753526c1..3cdbda053 100644--- a/apps/js-sdk/firecrawl/src/v2/client.ts+++ b/apps/js-sdk/firecrawl/src/v2/client.ts@@ -19,7 +19,7 @@ import {batchScrape as batchWaiter,} from "./methods/batch";import { startExtract, getExtractStatus, extract as extractWaiter } from "./methods/extract";-import { startAgent, getAgentStatus, agent as agentWaiter } from "./methods/agent";+import { startAgent, getAgentStatus, cancelAgent, agent as agentWaiter } from "./methods/agent";import { getConcurrency, getCreditUsage, getQueueStatus, getTokenUsage, getCreditUsageHistorical, getTokenUsageHistorical } from "./methods/usage";import type {Document,@@ -289,6 +289,14 @@ export class FirecrawlClient {async agent(args: Parameters<typeof startAgent>[1] & { pollInterval?: number; timeout?: number }): Promise<AgentStatusResponse> {return agentWaiter(this.http, args);}+ /**+ * Cancel an agent job.+ * @param jobId Agent job id.+ * @returns True if cancelled.+ */+ async cancelAgent(jobId: string): Promise<boolean> {+ return cancelAgent(this.http, jobId);+ }// Usage/** Current concurrency usage. */diff --git a/apps/js-sdk/firecrawl/src/v2/methods/agent.ts b/apps/js-sdk/firecrawl/src/v2/methods/agent.tsindex 34c04d79b..0f22206ff 100644--- a/apps/js-sdk/firecrawl/src/v2/methods/agent.ts+++ b/apps/js-sdk/firecrawl/src/v2/methods/agent.ts@@ -69,3 +69,14 @@ export async function agent(if (!jobId) return started as unknown as AgentStatusResponse;return waitAgent(http, jobId, args.pollInterval ?? 2, args.timeout);}++export async function cancelAgent(http: HttpClient, jobId: string): Promise<boolean> {+ try {+ const res = await http.delete<{ success: boolean }>(`/v2/agent/${jobId}`);+ if (res.status !== 200) throwForBadResponse(res, "cancel agent");+ return res.data?.success === true;+ } catch (err: any) {+ if (err?.isAxiosError) return normalizeAxiosError(err, "cancel agent");+ throw err;+ }+}diff --git a/apps/python-sdk/firecrawl/__init__.py b/apps/python-sdk/firecrawl/__init__.pyindex 731418692..cfd581b94 100644--- a/apps/python-sdk/firecrawl/__init__.py+++ b/apps/python-sdk/firecrawl/__init__.py@@ -17,7 +17,7 @@ from .v1 import (V1ChangeTrackingOptions,)-__version__ = "4.11.0"+__version__ = "4.11.1"# Define the logger for the Firecrawl projectlogger: logging.Logger = logging.getLogger("firecrawl")diff --git a/apps/python-sdk/firecrawl/v2/client.py b/apps/python-sdk/firecrawl/v2/client.pyindex 80002a199..243b72c1c 100644--- a/apps/python-sdk/firecrawl/v2/client.py+++ b/apps/python-sdk/firecrawl/v2/client.py@@ -824,6 +824,17 @@ class FirecrawlClient:"""return agent_module.get_agent_status(self.http_client, job_id)+ def cancel_agent(self, job_id: str) -> bool:+ """Cancel a running agent job.++ Args:+ job_id: Agent job ID++ Returns:+ True if the agent was cancelled+ """+ return agent_module.cancel_agent(self.http_client, job_id)+def get_concurrency(self):"""Get current concurrency and maximum allowed for this team/key (v2)."""return usage_methods.get_concurrency(self.http_client)diff --git a/apps/python-sdk/firecrawl/v2/client_async.py b/apps/python-sdk/firecrawl/v2/client_async.pyindex 0012fb88c..6b7468cd5 100644--- a/apps/python-sdk/firecrawl/v2/client_async.py+++ b/apps/python-sdk/firecrawl/v2/client_async.py@@ -351,6 +351,17 @@ class AsyncFirecrawlClient:integration=integration,)+ async def cancel_agent(self, job_id: str) -> bool:+ """Cancel a running agent job.++ Args:+ job_id: Agent job ID++ Returns:+ True if the agent was cancelled+ """+ return await async_agent.cancel_agent(self.async_http_client, job_id)+# Usage endpointsasync def get_concurrency(self):from .methods.aio import usage as async_usage # type: ignore[attr-defined]diff --git a/apps/python-sdk/firecrawl/v2/methods/agent.py b/apps/python-sdk/firecrawl/v2/methods/agent.pyindex ec9940331..a143d6b1e 100644--- a/apps/python-sdk/firecrawl/v2/methods/agent.py+++ b/apps/python-sdk/firecrawl/v2/methods/agent.py@@ -100,3 +100,23 @@ def agent(if not job_id:return startedreturn wait_agent(client, job_id, poll_interval=poll_interval, timeout=timeout)+++def cancel_agent(client: HttpClient, job_id: str) -> bool:+ """+ Cancel a running agent job.++ Args:+ client: HTTP client instance+ job_id: ID of the agent job to cancel++ Returns:+ bool: True if the agent was cancelled, False otherwise++ Raises:+ Exception: If the cancellation fails+ """+ resp = client.delete(f"/v2/agent/{job_id}")+ if not resp.ok:+ handle_response_error(resp, "cancel agent")+ return resp.json().get("success", False)diff --git a/apps/python-sdk/firecrawl/v2/methods/aio/agent.py b/apps/python-sdk/firecrawl/v2/methods/aio/agent.pyindex 1f346fbbb..289b1f52f 100644--- a/apps/python-sdk/firecrawl/v2/methods/aio/agent.py+++ b/apps/python-sdk/firecrawl/v2/methods/aio/agent.py@@ -95,3 +95,21 @@ async def agent(if not job_id:return startedreturn await wait_agent(client, job_id, poll_interval=poll_interval, timeout=timeout)+++async def cancel_agent(client: AsyncHttpClient, job_id: str) -> bool:+ """+ Cancel a running agent job.++ Args:+ client: Async HTTP client instance+ job_id: ID of the agent job to cancel++ Returns:+ bool: True if the agent was cancelled, False otherwise++ Raises:+ Exception: If the cancellation fails+ """+ resp = await client.delete(f"/v2/agent/{job_id}")+ return resp.json().get("success", False)