a2ui-project / a2ui-project/a2ui

refactor(web_core): extract shared Zod schema introspection and metadata utilities

未关闭
#2,443 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
P3 type: feature/enhancement
主要语言
TypeScript
星标
16.4k
派生
1.3k
平均合并
3 天 15 小时
30 天内合并 PR
134

描述

## Overview

`GenericBinder` (`renderers/web_core/src/v0_9/rendering/generic-binder.ts`) and `NodeResolver` (`renderers/web_core/src/v0_9/nodes/ref-fields.ts`) both independently inspect Zod schemas:
1. Accessing private `_def` internals (`typeName`, `innerType`, `description`, `options`, `shape()`).
2. Duplicating unwrapping loops for `ZodOptional`, `ZodNullable`, `ZodDefault`, and `ZodEffects`.
3. Defining duplicate schema reference strings (`REF:common_types.json#/$defs/...`).

## Goals

- **Centralize Schema Constants**: Export canonical reference constants (`CHILD_LIST_REF`, `COMPONENT_ID_REF`, `ACTION_REF`, `DATA_BINDING_REF`) from a central location (`renderers/web_core/src/v0_9/schema/constants.ts` or `common-types.ts`).
- **Shared Schema Introspection Utility**: Consolidate unwrapping logic into a dedicated helper module (`renderers/web_core/src/v0_9/schema/schema-reflection.ts`) so callers avoid accessing `_def` directly.
- **Extend Schema Metadata**: Broaden the `a2uiChildRef` metadata pattern introduced in PR #2393 (`markChildRef` / `childRefKindOf`) to `Action` and `Dynamic*` schemas (`a2uiKind: 'action' | 'dynamic' | 'child-list' | 'component-id'`).

## References

- PR #2359: https://github.com/a2ui-project/a2ui/pull/2359
- PR #2393: Node layer schema metadata implementation (commit `3a2f5f24`)

贡献指南

打开贡献指南

调研方向

首先阅读提到的两个文件:`renderers/web_core/src/v0_9/rendering/generic-binder.ts` 和 `renderers/web_core/src/v0_9/nodes/ref-fields.ts`。检查它们如何通过 `_def` 检查 Zod schemas。查看 PR #2393,以了解现有的 `a2uiChildRef` metadata 模式。目标是将共享逻辑提取到新的 utility modules 中,可能位于 `renderers/web_core/src/v0_9/schema/`。当从原始文件中移除重复的 introspection 代码,并将其替换为对新的共享 utilities 的调用时,即完成此任务。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
backend-api-design, tooling
Issue 类型
重构
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。