MCPcopy Index your code
hub / github.com/anomalyco/opencode / collect

Function collect

packages/opencode/src/tool/registry.ts:352–370  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

350 const registry = z.registry<Record<string, unknown>>()
351 const seen = new WeakSet<object>()
352 const collect = (value: unknown) => {
353 if (typeof value !== "object" || value === null) return
354 if (seen.has(value)) return
355 seen.add(value)
356
357 if (isZodType(value)) {
358 const metadata = typeof value.meta === "function" ? value.meta() : undefined
359 const description = typeof value.description === "string" ? value.description : undefined
360 const merged = {
361 ...(metadata && typeof metadata === "object" ? metadata : {}),
362 ...(description ? { description } : {}),
363 }
364 if (Object.keys(merged).length) registry.add(value, merged)
365 collect(value._zod.def)
366 return
367 }
368
369 for (const item of Object.values(value)) collect(item)
370 }
371 collect(schema)
372 return registry
373}

Callers 2

zodMetadataRegistryFunction · 0.70
shell.tsFile · 0.70

Calls 3

isZodTypeFunction · 0.85
addMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected