diff --git a/README.mbt.md b/README.mbt.md index 7b11417..afd60f8 100644 --- a/README.mbt.md +++ b/README.mbt.md @@ -25,7 +25,7 @@ In LLM Tool Calling, the model often produces **multiple errors at once** and ** ## 🚀 Quick Start -```mbt nocheck +```moonbit nocheck let schema = @moon_zod.object({ "name": @moon_zod.string().min(2).max(50), "age": @moon_zod.number().int().min(0).max(150), @@ -221,7 +221,7 @@ moon run examples/json2schema # JSON → moon_zod schema | `object(Map[String, Schema], required_error?, invalid_type_error?)` | Validates objects. **Default: Strip mode** | | `enum_values(Array[String], required_error?, invalid_type_error?)` | Fixed set of allowed string values | | `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**: Constant value validation — only accepts exact JSON match | -| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent | +| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent, need to truly implement | | `any(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value (pass-through) | | `unknown(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value as unknown (semantic marker) | | `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**: Transform raw input first, then validate against inner schema | @@ -300,7 +300,7 @@ moon run examples/json2schema # JSON → moon_zod schema ### Core Types -```mbt nocheck +```moonbit nocheck ///| pub struct ValidationError { path : String @@ -331,7 +331,7 @@ moon run cmd/json2schema -- '{"hello": "world"}' Output (copy-paste ready moon_zod code): -```moonbit +```moonbit nocheck @moon_zod.object({ "hello": @moon_zod.string(), }) @@ -369,7 +369,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json Output: -```moonbit +```moonbit nocheck @moon_zod.object({ "name": @moon_zod.string().min(2), "age": @moon_zod.number().int().min(0).max(150), @@ -397,12 +397,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ Output: -```moonbit +```moonbit nocheck +///| pub struct Root { name : String - age : Int64 // int + age : Int64 // int } derive(ToJson, FromJson) +///| pub fn Root::to_schema() -> @moon_zod.Schema { let root = @moon_zod.object({ "name": @moon_zod.string(), @@ -558,7 +560,7 @@ Schema-to-Prompt (TS interface): ← auto-generated by schema_to_prompt( moon_zod is designed for the **error feedback loop** — the key pattern that makes AI agents reliable: -```mbt nocheck +```moonbit nocheck ///| /// Retry loop: validate → collect errors → feed back → retry fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) { @@ -611,13 +613,33 @@ Product → uses type name `Product` Then **LLM sees only the definitions it needs**, reducing token count and improving clarity. **Example usage:** -```mbt nocheck +```moonbit nocheck // Define named schemas -let user_schema = @moon_zod.object({ ... }).name("User") -let order_schema = @moon_zod.object({ ... }).name("Order") -let product_schema = @moon_zod.object({ ... }).name("Product") + +///| +let user_schema = @moon_zod.object( + { + ... + }, +).name("User") + +///| +let order_schema = @moon_zod.object( + { + ... + }, +).name("Order") + +///| +let product_schema = @moon_zod.object( + { + ... + }, +).name("Product") // Auto-extract + generate modular prompt + +///| let prompt = @moon_zod.schema_to_prompt_named(user_schema) // Output: // export interface User { ... } diff --git a/README_zh.mbt.md b/README_zh.mbt.md index 02d8563..b97efe2 100644 --- a/README_zh.mbt.md +++ b/README_zh.mbt.md @@ -25,7 +25,7 @@ MoonBit 运行时 JSON Schema 校验库,受 [Zod](https://zod.dev) 和 [Pydant ## 🚀 快速开始 -```mbt nocheck +```moonbit nocheck let schema = @moon_zod.object({ "name": @moon_zod.string().min(2).max(50), "age": @moon_zod.number().int().min(0).max(150), @@ -216,7 +216,7 @@ moon run examples/json2schema # JSON → moon_zod Schema | `object(Map[String, Schema], required_error?, invalid_type_error?)` | 校验对象。**默认:Strip 模式** | | `enum_values(Array[String], required_error?, invalid_type_error?)` | 固定的允许字符串值集合 | | `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**:常量值校验 — 仅接受完全匹配的 JSON | -| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图 | +| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图,有待真正实现 | | `any(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值(透传) | | `unknown(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值作为未知类型(语义标记) | | `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**:先转换原始输入,再针对内部 schema 进行校验 | @@ -295,7 +295,7 @@ moon run examples/json2schema # JSON → moon_zod Schema ### 核心类型 -```mbt nocheck +```moonbit nocheck ///| pub struct ValidationError { path : String @@ -326,7 +326,7 @@ moon run cmd/json2schema -- '{"hello": "world"}' 输出(可直接复制粘贴的moon_zod代码): -```moonbit +```moonbit nocheck @moon_zod.object({ "hello": @moon_zod.string(), }) @@ -364,7 +364,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json 输出: -```moonbit +```moonbit nocheck @moon_zod.object({ "name": @moon_zod.string().min(2), "age": @moon_zod.number().int().min(0).max(150), @@ -392,12 +392,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ 输出: -```moonbit +```moonbit nocheck +///| pub struct Root { name : String - age : Int64 // int + age : Int64 // int } derive(ToJson, FromJson) +///| pub fn Root::to_schema() -> @moon_zod.Schema { let root = @moon_zod.object({ "name": @moon_zod.string(), @@ -550,7 +552,7 @@ Schema-to-Prompt (TS 接口): ← 由 schema_to_prompt() 自动 moon_zod 为**错误反馈循环**而设计 — 这是使 AI 智能体可靠的关键模式: -```mbt nocheck +```moonbit nocheck ///| /// 重试循环:校验 → 收集错误 → 反馈 → 重试 fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) { @@ -603,13 +605,33 @@ Product → 使用类型名称 `Product` 然后 **LLM 仅看到它需要的定义**,减少 Token 计数并提高清晰度。 **使用示例:** -```mbt nocheck +```moonbit nocheck // 定义命名 Schema -let user_schema = @moon_zod.object({ ... }).name("User") -let order_schema = @moon_zod.object({ ... }).name("Order") -let product_schema = @moon_zod.object({ ... }).name("Product") + +///| +let user_schema = @moon_zod.object( + { + ... + }, +).name("User") + +///| +let order_schema = @moon_zod.object( + { + ... + }, +).name("Order") + +///| +let product_schema = @moon_zod.object( + { + ... + }, +).name("Product") // 自动提取 + 生成模块化提示词 + +///| let prompt = @moon_zod.schema_to_prompt_named(user_schema) // 输出: // export interface User { ... } diff --git a/docs/API.md b/docs/API.md index 65bb9db..5d7d57d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -13,7 +13,7 @@ | `object(Map[String, Schema], required_error?, invalid_type_error?)` | Validates objects. **Default: Strip mode** | | `enum_values(Array[String], required_error?, invalid_type_error?)` | Fixed set of allowed string values | | `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**: Constant value validation — only accepts exact JSON match | -| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent | +| `bigint(required_error?, invalid_type_error?)` | **Phase 37**: Semantic alias for `number().int()` — expresses big integer intent, need to truly implement | | `any(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value (pass-through) | | `unknown(required_error?, invalid_type_error?)` | **Phase 39**: Accepts any JSON value as unknown (semantic marker) | | `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**: Transform raw input first, then validate against inner schema | @@ -92,7 +92,7 @@ ### Core Types -```mbt nocheck +```moonbit nocheck ///| pub struct ValidationError { path : String diff --git a/docs/CLI.md b/docs/CLI.md index 88e84f2..8c8b52a 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -8,7 +8,7 @@ moon run cmd/json2schema -- '{"hello": "world"}' Output (copy-paste ready moon_zod code): -```moonbit +```moonbit nocheck @moon_zod.object({ "hello": @moon_zod.string(), }) @@ -46,7 +46,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json Output: -```moonbit +```moonbit nocheck @moon_zod.object({ "name": @moon_zod.string().min(2), "age": @moon_zod.number().int().min(0).max(150), @@ -74,12 +74,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ Output: -```moonbit +```moonbit nocheck +///| pub struct Root { name : String - age : Int64 // int + age : Int64 // int } derive(ToJson, FromJson) +///| pub fn Root::to_schema() -> @moon_zod.Schema { let root = @moon_zod.object({ "name": @moon_zod.string(), diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index ad8debb..1b8fd4e 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -96,7 +96,7 @@ Schema-to-Prompt (TS interface): ← auto-generated by schema_to_prompt( moon_zod is designed for the **error feedback loop** — the key pattern that makes AI agents reliable: -```mbt nocheck +```moonbit nocheck ///| /// Retry loop: validate → collect errors → feed back → retry fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) { @@ -149,13 +149,33 @@ Product → uses type name `Product` Then **LLM sees only the definitions it needs**, reducing token count and improving clarity. **Example usage:** -```mbt nocheck +```moonbit nocheck // Define named schemas -let user_schema = @moon_zod.object({ ... }).name("User") -let order_schema = @moon_zod.object({ ... }).name("Order") -let product_schema = @moon_zod.object({ ... }).name("Product") + +///| +let user_schema = @moon_zod.object( + { + ... + }, +).name("User") + +///| +let order_schema = @moon_zod.object( + { + ... + }, +).name("Order") + +///| +let product_schema = @moon_zod.object( + { + ... + }, +).name("Product") // Auto-extract + generate modular prompt + +///| let prompt = @moon_zod.schema_to_prompt_named(user_schema) // Output: // export interface User { ... } diff --git a/docs/INFO.md b/docs/INFO.md index 6ecd5cd..3857aae 100644 --- a/docs/INFO.md +++ b/docs/INFO.md @@ -15,7 +15,7 @@ In LLM Tool Calling, the model often produces **multiple errors at once** and ** ## 🚀 Quick Start -```mbt nocheck +```moonbit nocheck let schema = @moon_zod.object({ "name": @moon_zod.string().min(2).max(50), "age": @moon_zod.number().int().min(0).max(150), diff --git a/docs/zh/API.md b/docs/zh/API.md index ab9efe7..10989df 100644 --- a/docs/zh/API.md +++ b/docs/zh/API.md @@ -13,7 +13,7 @@ | `object(Map[String, Schema], required_error?, invalid_type_error?)` | 校验对象。**默认:Strip 模式** | | `enum_values(Array[String], required_error?, invalid_type_error?)` | 固定的允许字符串值集合 | | `literal(Json, required_error?, invalid_type_error?)` | **Phase 32**:常量值校验 — 仅接受完全匹配的 JSON | -| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图 | +| `bigint(required_error?, invalid_type_error?)` | **Phase 37**:`number().int()` 的语义别名 — 表示大整数意图,有待真正实现 | | `any(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值(透传) | | `unknown(required_error?, invalid_type_error?)` | **Phase 39**:接受任何 JSON 值作为未知类型(语义标记) | | `preprocess((Json) -> Result[Json, String], Schema, required_error?, invalid_type_error?)` | **Phase 39**:先转换原始输入,再针对内部 schema 进行校验 | @@ -92,7 +92,7 @@ ### 核心类型 -```mbt nocheck +```moonbit nocheck ///| pub struct ValidationError { path : String diff --git a/docs/zh/CLI.md b/docs/zh/CLI.md index e42ed11..996dc6a 100644 --- a/docs/zh/CLI.md +++ b/docs/zh/CLI.md @@ -8,7 +8,7 @@ moon run cmd/json2schema -- '{"hello": "world"}' 输出(可直接复制粘贴的moon_zod代码): -```moonbit +```moonbit nocheck @moon_zod.object({ "hello": @moon_zod.string(), }) @@ -46,7 +46,7 @@ moon run cmd/json2schema -- --from-json-schema --schema-file schema.json 输出: -```moonbit +```moonbit nocheck @moon_zod.object({ "name": @moon_zod.string().min(2), "age": @moon_zod.number().int().min(0).max(150), @@ -74,12 +74,14 @@ moon run cmd/gen-struct -- --schema '{"type":"object","properties":{"name":{"typ 输出: -```moonbit +```moonbit nocheck +///| pub struct Root { name : String - age : Int64 // int + age : Int64 // int } derive(ToJson, FromJson) +///| pub fn Root::to_schema() -> @moon_zod.Schema { let root = @moon_zod.object({ "name": @moon_zod.string(), diff --git a/docs/zh/EXAMPLES.md b/docs/zh/EXAMPLES.md index 96e4d0e..26e5a49 100644 --- a/docs/zh/EXAMPLES.md +++ b/docs/zh/EXAMPLES.md @@ -97,7 +97,7 @@ Schema-to-Prompt (TS 接口): ← 由 schema_to_prompt() 自动 moon_zod 为**错误反馈循环**而设计 — 这是使 AI 智能体可靠的关键模式: -```mbt nocheck +```moonbit nocheck ///| /// 重试循环:校验 → 收集错误 → 反馈 → 重试 fn call_llm_with_retry(schema : @moon_zod.Schema, times : Int) { @@ -150,13 +150,33 @@ Product → 使用类型名称 `Product` 然后 **LLM 仅看到它需要的定义**,减少 Token 计数并提高清晰度。 **使用示例:** -```mbt nocheck +```moonbit nocheck // 定义命名 Schema -let user_schema = @moon_zod.object({ ... }).name("User") -let order_schema = @moon_zod.object({ ... }).name("Order") -let product_schema = @moon_zod.object({ ... }).name("Product") + +///| +let user_schema = @moon_zod.object( + { + ... + }, +).name("User") + +///| +let order_schema = @moon_zod.object( + { + ... + }, +).name("Order") + +///| +let product_schema = @moon_zod.object( + { + ... + }, +).name("Product") // 自动提取 + 生成模块化提示词 + +///| let prompt = @moon_zod.schema_to_prompt_named(user_schema) // 输出: // export interface User { ... } diff --git a/docs/zh/INFO.md b/docs/zh/INFO.md index 81ab6a5..80e55ac 100644 --- a/docs/zh/INFO.md +++ b/docs/zh/INFO.md @@ -15,7 +15,7 @@ ## 🚀 快速开始 -```mbt nocheck +```moonbit nocheck let schema = @moon_zod.object({ "name": @moon_zod.string().min(2).max(50), "age": @moon_zod.number().int().min(0).max(150),