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
Nsc/new agent threads fix (#4511)
Nicolase2743958b427
diff --git a/apps/api/src/controllers/v2/agent-skill.ts b/apps/api/src/controllers/v2/agent-skill.tsnew file mode 100644index 000000000..ae291c134--- /dev/null+++ b/apps/api/src/controllers/v2/agent-skill.ts@@ -0,0 +1,41 @@+import { Response } from "express";+import { config } from "../../config";+import { supabaseGetAgentRequestByIdDirect } from "../../lib/supabase-jobs";+import { AgentSkillResponse, RequestWithAuth } from "./types";++export async function agentSkillController(+ req: RequestWithAuth<{ jobId: string }, AgentSkillResponse, any>,+ res: Response<AgentSkillResponse>,+) {+ 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 query = req.query.refresh === "1" ? "?refresh=1" : "";+ const upstream = await fetch(+ `${config.EXTRACT_V3_BETA_URL}/internal/extracts/${req.params.jobId}/skill${query}`,+ {+ headers: {+ Authorization: `Bearer ${config.AGENT_INTEROP_SECRET}`,+ },+ },+ );++ const body = (await upstream.json()) as AgentSkillResponse;++ // 404 (skills off, or nothing stored) and 409 (run still going, or it+ // produced no data) both mean "no skill yet" to the caller, so the upstream+ // status carries through rather than collapsing into a 500.+ return res.status(upstream.status).json(body);+}diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.tsindex 2673b4469..366049fbb 100644--- a/apps/api/src/controllers/v2/types.ts+++ b/apps/api/src/controllers/v2/types.ts@@ -1726,6 +1726,28 @@ export type AgentTraceResponse =}>;};+/**+ * A finished run distilled into something reusable: a SKILL.md to paste into a+ * coding agent, and a workflow script that reproduces the run through the API.+ * The upstream shape is passed through verbatim.+ */+export type AgentSkillResponse =+ | ErrorResponse+ | {+ success: true;+ id: string;+ skill: {+ name: string;+ spec: object;+ skillMd: string;+ workflow: string;+ schema: string;+ };+ blueprint: object;+ generatedAt: string;+ generated: boolean;+ };+export type AgentSnapshotResponse =| ErrorResponse| {diff --git a/apps/api/src/routes/v2.ts b/apps/api/src/routes/v2.tsindex fae4ecd5f..c6f9f1646 100644--- a/apps/api/src/routes/v2.ts+++ b/apps/api/src/routes/v2.ts@@ -57,6 +57,7 @@ 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 { agentSkillController } from "../controllers/v2/agent-skill";import { agentThreadController } from "../controllers/v2/agent-thread";import {browserCreateController,@@ -414,6 +415,13 @@ v2Router.get(wrap(agentTraceController),);+v2Router.get(+ "/agent/:jobId/skill",+ authMiddleware(RateLimiterMode.ExtractStatus),+ validateJobIdParam,+ wrap(agentSkillController),+);+v2Router.get("/agent/:jobId/snapshots/:snapshotId",authMiddleware(RateLimiterMode.ExtractStatus),