mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 09:07:46 +02:00
Fix heartbeat runs on legacy SQL_ASCII databases
This commit is contained in:
1 parent
a91b2d2d62
commit
4d730c8747
2 files changed
+1
-73
No files matched your search
@@ -212,6 +212,7 @@ export function appendWithByteCap(prev: string, chunk: string, cap = MAX_CAPTURE
|
||||
while (start < buffer.length && (buffer[start]! & 0xc0) === 0x80) start += 1;
|
||||
return buffer.subarray(start).toString("utf8");
|
||||
}
|
||||
|
||||
function resumeReadable(readable: { resume: () => unknown; destroyed?: boolean } | null | undefined) {
|
||||
if (!readable || readable.destroyed) return;
|
||||
readable.resume();
|
||||
|
||||
@@ -630,79 +630,6 @@ const heartbeatRunIssueSummaryColumns = {
|
||||
function appendExcerpt(prev: string, chunk: string) {
|
||||
return appendWithByteCap(prev, chunk, MAX_EXCERPT_BYTES);
|
||||
}
|
||||
|
||||
function truncateRunEventString(value: string) {
|
||||
if (value.length <= MAX_RUN_EVENT_PAYLOAD_STRING_CHARS) return value;
|
||||
const omittedChars = value.length - MAX_RUN_EVENT_PAYLOAD_STRING_CHARS;
|
||||
return `${value.slice(0, MAX_RUN_EVENT_PAYLOAD_STRING_CHARS)}\n[truncated ${omittedChars} chars]`;
|
||||
}
|
||||
|
||||
function boundRunEventValue(value: unknown, depth: number, seen: WeakSet<object>): unknown {
|
||||
if (typeof value === "string") {
|
||||
return truncateRunEventString(value);
|
||||
}
|
||||
if (
|
||||
value === null
|
||||
|| typeof value === "number"
|
||||
|| typeof value === "boolean"
|
||||
) {
|
||||
return value;
|
||||
}
|
||||
if (value instanceof Date) {
|
||||
return value.toISOString();
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
if (depth >= MAX_RUN_EVENT_PAYLOAD_DEPTH) {
|
||||
return {
|
||||
_truncated: true,
|
||||
type: "array",
|
||||
originalLength: value.length,
|
||||
};
|
||||
}
|
||||
const bounded = value
|
||||
.slice(0, MAX_RUN_EVENT_PAYLOAD_ARRAY_ITEMS)
|
||||
.map((entry) => boundRunEventValue(entry, depth + 1, seen));
|
||||
if (value.length > MAX_RUN_EVENT_PAYLOAD_ARRAY_ITEMS) {
|
||||
bounded.push({
|
||||
_truncated: true,
|
||||
omittedItems: value.length - MAX_RUN_EVENT_PAYLOAD_ARRAY_ITEMS,
|
||||
});
|
||||
}
|
||||
return bounded;
|
||||
}
|
||||
if (typeof value !== "object" || value === undefined) {
|
||||
return null;
|
||||
}
|
||||
if (seen.has(value)) {
|
||||
return "[Circular]";
|
||||
}
|
||||
seen.add(value);
|
||||
const entries = Object.entries(value as Record<string, unknown>);
|
||||
if (depth >= MAX_RUN_EVENT_PAYLOAD_DEPTH) {
|
||||
const bounded = {
|
||||
_truncated: true,
|
||||
type: "object",
|
||||
keys: entries.map(([key]) => key).slice(0, 20),
|
||||
};
|
||||
seen.delete(value);
|
||||
return bounded;
|
||||
}
|
||||
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const [key, entryValue] of entries.slice(0, MAX_RUN_EVENT_PAYLOAD_OBJECT_KEYS)) {
|
||||
out[key] = boundRunEventValue(entryValue, depth + 1, seen);
|
||||
}
|
||||
if (entries.length > MAX_RUN_EVENT_PAYLOAD_OBJECT_KEYS) {
|
||||
out._truncated = true;
|
||||
out._omittedKeys = entries.length - MAX_RUN_EVENT_PAYLOAD_OBJECT_KEYS;
|
||||
}
|
||||
seen.delete(value);
|
||||
return out;
|
||||
}
|
||||
|
||||
export function boundHeartbeatRunEventPayloadForStorage(payload: Record<string, unknown>): Record<string, unknown> {
|
||||
const bounded = boundRunEventValue(payload, 0, new WeakSet());
|
||||
return parseObject(bounded) ?? { _truncated: true };
|
||||
}
|
||||
|
||||
function truncateRunEventString(value: string) {
|
||||
|
||||
Reference in new issue
Block a user