resolve main merge conflicts for alert context and beads state

This commit is contained in:
dirtydishes 2026-05-17 21:12:19 -04:00
commit dc932cf18e
11 changed files with 843 additions and 153 deletions

View file

@ -0,0 +1,21 @@
import { z } from "zod";
export const alertContextTraceIdSchema = z
.string()
.trim()
.min(1)
.max(256)
.regex(/^[A-Za-z0-9][A-Za-z0-9:_./-]*$/);
export const isAlertContextPath = (pathname: string): boolean => {
return /^\/flow\/alerts\/[^/]+\/context$/.test(pathname);
};
export const parseAlertContextTraceIdPath = (pathname: string): string | null => {
if (!isAlertContextPath(pathname)) {
return null;
}
const encodedTraceId = pathname.slice("/flow/alerts/".length, -"/context".length);
return alertContextTraceIdSchema.parse(decodeURIComponent(encodedTraceId));
};

View file

@ -47,6 +47,7 @@ import {
ensureOptionPrintsTable,
fetchAlertsAfter,
fetchAlertsBefore,
fetchAlertContextByTraceId,
fetchClassifierHitsAfter,
fetchClassifierHitsBefore,
fetchSmartMoneyEventsAfter,
@ -119,6 +120,7 @@ import {
resolveLiveStateConfig,
shouldFanoutLiveEvent
} from "./live";
import { isAlertContextPath, parseAlertContextTraceIdPath } from "./alert-context";
import { parseOptionPrintQuery } from "./option-queries";
import {
buildSyntheticDerivedStatus,
@ -1488,6 +1490,25 @@ const run = async () => {
return jsonResponse({ data });
}
if (req.method === "GET" && isAlertContextPath(url.pathname)) {
try {
const traceId = parseAlertContextTraceIdPath(url.pathname);
if (traceId === null) {
return jsonResponse({ error: "not found" }, 404);
}
const data = await fetchAlertContextByTraceId(clickhouse, traceId);
return jsonResponse(data);
} catch (error) {
return jsonResponse(
{
error: "invalid alert context query",
detail: error instanceof Error ? error.message : String(error)
},
400
);
}
}
if (req.method === "GET" && url.pathname === "/history/options") {
try {
const { beforeTs, beforeSeq, limit } = parseBeforeParams(url);