MCPcopy Index your code
hub / github.com/simstudioai/sim / trimFinalBlockLogsForEventData

Function trimFinalBlockLogsForEventData

apps/sim/lib/execution/event-buffer.ts:204–238  ·  view source on GitHub ↗
(data: unknown)

Source from the content-addressed store, hash-verified

202}
203
204function trimFinalBlockLogsForEventData(data: unknown): unknown {
205 if (!data || typeof data !== 'object' || Array.isArray(data)) return data
206
207 const record = data as Record<string, unknown>
208 const finalBlockLogs = record.finalBlockLogs
209 if (!Array.isArray(finalBlockLogs)) return data
210 const originalSize = getJsonSize(data)
211 if (originalSize !== null && originalSize <= LARGE_VALUE_THRESHOLD_BYTES) return data
212
213 const total = finalBlockLogs.length
214 let logs = finalBlockLogs
215 let trimmed: Record<string, unknown> = {
216 ...record,
217 finalBlockLogs: logs,
218 finalBlockLogsTruncated: true,
219 finalBlockLogsTotal: total,
220 }
221
222 while (logs.length > 0) {
223 const size = getJsonSize(trimmed)
224 if (size !== null && size <= LARGE_VALUE_THRESHOLD_BYTES) {
225 return trimmed
226 }
227
228 logs = logs.length === 1 ? [] : logs.slice(Math.ceil(logs.length / 2))
229 trimmed = {
230 ...record,
231 finalBlockLogs: logs,
232 finalBlockLogsTruncated: true,
233 finalBlockLogsTotal: total,
234 }
235 }
236
237 return trimmed
238}
239
240export interface ExecutionStreamMeta {
241 status: ExecutionStreamStatus

Callers 1

compactEventForBufferFunction · 0.85

Calls 1

getJsonSizeFunction · 0.85

Tested by

no test coverage detected