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

Function grepField

apps/sim/lib/logs/log-views.ts:240–291  ·  view source on GitHub ↗
(
  value: unknown,
  field: 'input' | 'output',
  span: TraceSpan,
  ctx: LogViewContext,
  state: GrepState
)

Source from the content-addressed store, hash-verified

238}
239
240async 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
293function safeStringify(value: unknown): string {
294 if (value === undefined || value === null) return ''

Callers 1

walkFunction · 0.85

Calls 7

isLargeArrayManifestFunction · 0.90
isLargeValueRefFunction · 0.90
materializeLargeValueRefFunction · 0.90
doneFunction · 0.85
recordIfMatchFunction · 0.85
safeStringifyFunction · 0.70

Tested by

no test coverage detected