MCPcopy Create free account
hub / github.com/hashintel/hash / setupAnalysisHandler

Function setupAnalysisHandler

apps/hash-api/src/analysis/setup-analysis-handler.ts:54–105  ·  view source on GitHub ↗
(app: Express, cache: Keyv)

Source from the content-addressed store, hash-verified

52 * storage (the data plane). Artifact bytes never pass through the API.
53 */
54export const setupAnalysisHandler = (app: Express, cache: Keyv) => {
55 ensureAnalysesRegistered();
56
57 app.post("/api/analysis", analysisRateLimiter, async (req, res) => {
58 const { user } = req;
59 if (!user) {
60 res.status(401).json({ error: "Authentication required" });
61 return;
62 }
63
64 const body = req.body as AnalysisRequest | undefined;
65 if (!body || !Array.isArray(body.requests)) {
66 res.status(400).json({
67 error: "Request body must be { requests: AnalysisInvocation[] }",
68 });
69 return;
70 }
71
72 if (body.requests.length > MAX_BATCH_SIZE) {
73 res
74 .status(400)
75 .json({ error: `Too many requests (max ${MAX_BATCH_SIZE})` });
76 return;
77 }
78
79 const { graphApi, uploadProvider } = req.context;
80
81 const results = await Promise.all(
82 body.requests.map((invocation) =>
83 resolveInvocation({
84 invocation,
85 actorId: user.accountId,
86 graphApi,
87 uploadProvider,
88 cache,
89 }),
90 ),
91 );
92
93 for (const [index, result] of results.entries()) {
94 const invocation = body.requests[index]!;
95 telemetry.track(req, "analysis_run", {
96 analysis: invocation.analysis,
97 webId: invocation.webId,
98 status: result.status,
99 artifactCount: result.artifacts?.length ?? 0,
100 });
101 }
102
103 res.json({ results } satisfies AnalysisResponse);
104 });
105};

Callers 1

mainFunction · 0.90

Calls 6

resolveInvocationFunction · 0.90
ensureAnalysesRegisteredFunction · 0.85
jsonMethod · 0.80
trackMethod · 0.80
allMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected