schema

schema = 给 AI 和程序同时看的“结构合同(Contract)”

schema.ts 是 Agent 世界里的 interface.d.ts不是实现,是 约定。

 

1.定义“模型应该输出什么结构”,是给整个 Agent 系统定“目标形态”

2.作为 JSON 校验 / 修复的依据

3.成为 UI / SDK 的单一真相源(SSOT)

Element Plus 渲染、表单设计器、后端字段对齐都是消费同一个 schema.ts

前后端共用 TypeScript 声明文件,避免字段遗漏

schema.ts 正是那个“声明文件”

 

import { z } from "zod"

export const FieldSchema = z.object({
    name: z.string(),
    label: z.string(),
    type: z.enum(["input", "select", "date"]),
    required: z.boolean(),
    path: z.array(z.string()),
    message: z.string()
})

export const FormSchema = z.object({
    title: z.string(),
    fields: z.array(FieldSchema).min(1),
})

export type FormSchemaType = z.infer<typeof FormSchema>

 

posted on 2026-01-23 10:08  sss大辉  阅读(1)  评论(0)    收藏  举报

导航