mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
// Tails JSONL request logs for Codex media-path E2E assertions.
|
|
import {
|
|
createIncrementalLineReader,
|
|
resolvePositiveInteger,
|
|
} from "../incremental-line-reader.mjs";
|
|
|
|
const DEFAULT_MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
const DEFAULT_HISTORY_LIMIT = 1024;
|
|
|
|
type JsonlRequestTailOptions = {
|
|
historyLimit?: number;
|
|
maxReadBytes?: number;
|
|
};
|
|
|
|
export function createJsonlRequestTailer<T = unknown>(
|
|
filePath: string,
|
|
options: JsonlRequestTailOptions = {},
|
|
): { read(): T[] } {
|
|
const maxReadBytes = resolvePositiveInteger(options.maxReadBytes, DEFAULT_MAX_READ_BYTES);
|
|
const historyLimit = resolvePositiveInteger(options.historyLimit, DEFAULT_HISTORY_LIMIT);
|
|
const reader = createIncrementalLineReader(filePath, { maxReadBytes });
|
|
let requests: T[] = [];
|
|
|
|
function parseLine(line: string): T {
|
|
try {
|
|
return JSON.parse(line);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
throw new Error(`invalid app-server JSONL at ${filePath}: ${message}`, { cause: error });
|
|
}
|
|
}
|
|
|
|
return {
|
|
read() {
|
|
const { lines, reset } = reader.readLines();
|
|
if (reset) {
|
|
requests = [];
|
|
}
|
|
for (const line of lines) {
|
|
if (!line.trim()) {
|
|
continue;
|
|
}
|
|
requests.push(parseLine(line));
|
|
}
|
|
if (requests.length > historyLimit) {
|
|
requests = requests.slice(-historyLimit);
|
|
}
|
|
return requests;
|
|
},
|
|
};
|
|
}
|