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

Function zodMetadataRegistry

packages/opencode/src/tool/registry.ts:349–373  ·  view source on GitHub ↗
(schema: z.ZodType)

Source from the content-addressed store, hash-verified

347}
348
349function zodMetadataRegistry(schema: z.ZodType) {
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}
374
375function normalizeZodJsonSchema(value: unknown): unknown {
376 if (Array.isArray(value)) return value.map((item) => normalizeZodJsonSchema(item))

Callers 1

zodJsonSchemaFunction · 0.85

Calls 1

collectFunction · 0.70

Tested by

no test coverage detected