feat: unify JSON value schema DSL
This commit is contained in:
@@ -37,10 +37,11 @@ export function apply(ctx: Context) {
|
||||
```ts
|
||||
export const parameters = {
|
||||
path: { type: 'string', required: true },
|
||||
limit: { type: 'number' },
|
||||
limit: { type: 'integer' },
|
||||
recursive: { type: 'boolean' },
|
||||
parent: { type: 'null' },
|
||||
}
|
||||
// Inferred type: { path: string; limit?: number; recursive?: boolean }
|
||||
// Inferred type: { path: string; limit?: number; recursive?: boolean; parent?: null }
|
||||
```
|
||||
|
||||
### Enums
|
||||
@@ -49,7 +50,7 @@ export const parameters = {
|
||||
export const parameters = {
|
||||
mode: { type: 'string', required: true, enum: ['read', 'write', 'append'] },
|
||||
}
|
||||
// Inferred type: { mode: string } (enum values are validated at runtime)
|
||||
// Inferred type: { mode: 'read' | 'write' | 'append' }
|
||||
```
|
||||
|
||||
### Nested objects
|
||||
@@ -58,13 +59,14 @@ export const parameters = {
|
||||
export const parameters = {
|
||||
options: {
|
||||
type: 'object',
|
||||
additionalProperties: true,
|
||||
properties: {
|
||||
timeout: { type: 'number' },
|
||||
retries: { type: 'number' },
|
||||
},
|
||||
},
|
||||
}
|
||||
// Inferred type: { options?: { timeout?: number; retries?: number } }
|
||||
// The declared fields are inferred; additional JSON-valued keys are allowed.
|
||||
```
|
||||
|
||||
### Arrays
|
||||
@@ -83,12 +85,16 @@ export const parameters = {
|
||||
|
||||
| Field | Type | Meaning |
|
||||
|------|------|------|
|
||||
| `type` | `'string' \| 'number' \| 'boolean' \| 'object' \| 'array'` | Value type |
|
||||
| `type` | `'string' \| 'number' \| 'integer' \| 'boolean' \| 'null' \| 'object' \| 'array' \| 'json'` | Value type; `json` accepts any lossless JSON value |
|
||||
| `required` | `true` | Marks the property required and affects inference |
|
||||
| `description` | `string` | Description sent to the model |
|
||||
| `enum` | `string[]` | Allowed string values |
|
||||
| `properties` | `SchemaSpec` | Nested properties for an object |
|
||||
| `items` | `SchemaProp` | Element schema for an array |
|
||||
| `enum` / `const` | matching scalar values | Allowed literal values, checked at author and runtime boundaries |
|
||||
| `properties` | `ParameterSchemaSpec` | Nested properties for an object |
|
||||
| `additionalProperties` | `true \| false` | Required on every explicit object node |
|
||||
| `items` | `ValueSchemaSpec` | Element schema for an array |
|
||||
| `oneOf` | at least two `ValueSchemaSpec` branches | Requires exactly one matching branch; used instead of `type` |
|
||||
|
||||
The outer `parameters` map is an implicit open object. Explicit nested objects choose their openness; raw JSON Schema registered without `defineTool` keeps JSON Schema's open-by-default behavior.
|
||||
|
||||
## The execute function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user