( value: unknown, field: 'input' | 'output', span: TraceSpan, ctx: LogViewContext, state: GrepState )
| 238 | } |
| 239 | |
| 240 | async function grepField( |
| 241 | value: unknown, |
| 242 | field: 'input' | 'output', |
| 243 | span: TraceSpan, |
| 244 | ctx: LogViewContext, |
| 245 | state: GrepState |
| 246 | ): Promise<void> { |
| 247 | if (done(state)) return |
| 248 | |
| 249 | if (isLargeArrayManifest(value)) { |
| 250 | let start = 0 |
| 251 | while (start < value.totalCount && !done(state)) { |
| 252 | if (state.slicesScanned >= state.maxSlicesScanned) { |
| 253 | state.truncated = true |
| 254 | break |
| 255 | } |
| 256 | let slice: unknown[] | null |
| 257 | try { |
| 258 | slice = await readLargeArrayManifestSlice(value, start, ARRAY_SLICE_BATCH, ctx) |
| 259 | } catch { |
| 260 | // Unavailable chunk: fall back to the manifest preview once and stop. |
| 261 | recordIfMatch(safeStringify(value.preview), field, span, state) |
| 262 | return |
| 263 | } |
| 264 | state.slicesScanned += 1 |
| 265 | if (slice.length === 0) break |
| 266 | recordIfMatch(safeStringify(slice), field, span, state) |
| 267 | start += ARRAY_SLICE_BATCH |
| 268 | // Release the batch before fetching the next so peak memory ~= one batch. |
| 269 | slice = null |
| 270 | } |
| 271 | return |
| 272 | } |
| 273 | |
| 274 | if (isLargeValueRef(value)) { |
| 275 | let materialized: unknown |
| 276 | try { |
| 277 | materialized = await materializeLargeValueRef(value, { |
| 278 | ...ctx, |
| 279 | maxBytes: ctx.maxBytes ?? SINGLE_REF_MAX_BYTES, |
| 280 | }) |
| 281 | } catch { |
| 282 | materialized = undefined |
| 283 | } |
| 284 | const text = |
| 285 | materialized === undefined ? safeStringify(value.preview) : safeStringify(materialized) |
| 286 | recordIfMatch(text, field, span, state) |
| 287 | return |
| 288 | } |
| 289 | |
| 290 | recordIfMatch(safeStringify(value), field, span, state) |
| 291 | } |
| 292 | |
| 293 | function safeStringify(value: unknown): string { |
| 294 | if (value === undefined || value === null) return '' |
no test coverage detected