sandbox-agent/factory/packages/frontend-errors/src/client.ts
Nathan Flurry d2346bafb3
Configure lefthook formatter checks (#231)
* Add lefthook formatter checks

* Fix SDK mode hydration

* Stabilize SDK mode integration test
2026-03-10 23:03:11 -07:00

35 lines
1.1 KiB
TypeScript

import type { FrontendErrorContext } from "./types.js";
interface FrontendErrorCollectorGlobal {
setContext: (context: FrontendErrorContext) => void;
}
declare global {
interface Window {
__OPENHANDOFF_FRONTEND_ERROR_COLLECTOR__?: FrontendErrorCollectorGlobal;
__OPENHANDOFF_FRONTEND_ERROR_CONTEXT__?: FrontendErrorContext;
}
}
export function setFrontendErrorContext(context: FrontendErrorContext): void {
if (typeof window === "undefined") {
return;
}
const nextContext = sanitizeContext(context);
window.__OPENHANDOFF_FRONTEND_ERROR_CONTEXT__ = {
...(window.__OPENHANDOFF_FRONTEND_ERROR_CONTEXT__ ?? {}),
...nextContext,
};
window.__OPENHANDOFF_FRONTEND_ERROR_COLLECTOR__?.setContext(nextContext);
}
function sanitizeContext(input: FrontendErrorContext): FrontendErrorContext {
const output: FrontendErrorContext = {};
for (const [key, value] of Object.entries(input)) {
if (value === null || value === undefined || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
output[key] = value;
}
}
return output;
}