refactor(observation): isolate document processing from capture orchestration

This commit is contained in:
Ljy-0827 authored and drakezhang committed 2026-09-09 15:54:41 +08:00
1 parent 36d0d91419
commit 388b3ae2d5
17 files changed
+1273 -2298

No files matched your search

@@ -0,0 +1,32 @@
function captureAbortError(): Error {
const error = new Error("observation aborted");
error.name = "AbortError";
return error;
}
export function isAbortError(error: unknown): boolean {
return (
typeof error === "object" &&
error !== null &&
(error as { name?: string }).name === "AbortError"
);
}
export function throwIfAborted(signal: AbortSignal | undefined): void {
if (signal?.aborted) throw captureAbortError();
}
/** Called only at bounded block boundaries, not once per node. */
export async function captureCheckpoint(signal?: AbortSignal): Promise<void> {
throwIfAborted(signal);
await new Promise<void>((resolve) => {
const channel = new MessageChannel();
channel.port1.onmessage = () => {
channel.port1.close();
channel.port2.close();
resolve();
};
channel.port2.postMessage(null);
});
throwIfAborted(signal);
}