Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 21 additions & 34 deletions agent-client-protocol-schema/src/v2/elicitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ pub struct StringPropertySchema {
/// Optional. Omitted and `null` are equivalent and mean there is no maximum length constraint.
#[serde(default)]
pub max_length: Option<u32>,
/// Pattern the string must match, in ECMA-262 regular expression syntax.
///
/// Optional. Omitted and `null` are equivalent and mean there is no pattern constraint.
#[cfg_attr(feature = "schemars", schemars(extend("format" = "regex")))]
#[serde(default)]
pub pattern: Option<String>,
/// String format.
///
/// Optional. Omitted and `null` are equivalent and mean there is no format constraint.
Expand Down Expand Up @@ -281,13 +275,6 @@ impl StringPropertySchema {
self
}

/// Pattern the string must match, in ECMA-262 regular expression syntax.
#[must_use]
pub fn pattern(mut self, pattern: impl IntoOption<String>) -> Self {
self.pattern = pattern.into_option();
self
}

/// String format.
#[must_use]
pub fn format(mut self, format: impl IntoOption<StringFormat>) -> Self {
Expand Down Expand Up @@ -2897,29 +2884,29 @@ mod tests {
}

#[test]
fn schema_string_pattern_serialization() {
let schema = ElicitationSchema::new().property(
"name",
StringPropertySchema::new()
.min_length(1)
.max_length(64)
.pattern("^[a-zA-Z_][a-zA-Z0-9_]*$"),
true,
);

let json = serde_json::to_value(&schema).unwrap();
assert_eq!(json["properties"]["name"]["type"], "string");
assert_eq!(
json["properties"]["name"]["pattern"],
"^[a-zA-Z_][a-zA-Z0-9_]*$"
);
fn schema_string_ignores_pattern() {
let schema: ElicitationSchema = serde_json::from_value(json!({
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 64,
"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
}
},
"required": ["name"]
}))
.unwrap();

let roundtripped: ElicitationSchema = serde_json::from_value(json).unwrap();
if let ElicitationPropertySchema::String(s) = roundtripped.properties.get("name").unwrap() {
assert_eq!(s.pattern.as_deref(), Some("^[a-zA-Z_][a-zA-Z0-9_]*$"));
} else {
let ElicitationPropertySchema::String(name) = schema.properties.get("name").unwrap() else {
panic!("expected String variant");
}
};
assert_eq!(name.min_length, Some(1));
assert_eq!(name.max_length, Some(64));

let json = serde_json::to_value(&schema).unwrap();
assert_eq!(json["properties"]["name"].get("pattern"), None);
}

#[test]
Expand Down
19 changes: 9 additions & 10 deletions docs/protocol/v2/draft/elicitation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,15 @@ progress actually resumes. `elicitation/complete` is not itself a state update.
`requestedSchema` is a flat object with `type: "object"`, `properties`, and
optional `required`, `title`, and `description`. Each property is one of:

| Property | Schema | Optional keywords |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| Text | `type: "string"` | `minLength`, `maxLength`, `pattern`, `format` (`email`, `uri`, `date`, `date-time`), `default` |
| Single select | `type: "string"` with `enum` (values) or `oneOf` (`const` and `title` options) | `default` |
| Number | `type: "number"` or `type: "integer"` | `minimum`, `maximum`, `default` |
| Boolean | `type: "boolean"` | `default` |
| Multi select | `type: "array"` with `items` of `{ "type": "string", "enum": [...] }` or `{ "anyOf": [...] }` (`const` and `title` options) | `minItems`, `maxItems`, `default` |

Every property may also have `title` and `description`. `pattern` uses
ECMA-262 regular expression syntax, as in JSON Schema. Clients treat an unknown
| Property | Schema | Optional keywords |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| Text | `type: "string"` | `minLength`, `maxLength`, `format` (`email`, `uri`, `date`, `date-time`), `default` |
| Single select | `type: "string"` with `enum` (values) or `oneOf` (`const` and `title` options) | `default` |
| Number | `type: "number"` or `type: "integer"` | `minimum`, `maximum`, `default` |
| Boolean | `type: "boolean"` | `default` |
| Multi select | `type: "array"` with `items` of `{ "type": "string", "enum": [...] }` or `{ "anyOf": [...] }` (`const` and `title` options) | `minItems`, `maxItems`, `default` |

Every property may also have `title` and `description`. Clients treat an unknown
`format` as plain text. Accepted `content` maps each answered property name to its value: a string for text and single-select properties, a number for `number` and `integer`, a boolean for `boolean`, and an array of strings for multi-select. Unanswered properties are omitted, not set to `null`. Custom or future property types may use other JSON values.

Clients **SHOULD** validate submitted values before responding, and Agents
Expand Down
16 changes: 0 additions & 16 deletions docs/protocol/v2/draft/schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5484,14 +5484,6 @@ Optional. Omitted and `null` are equivalent and mean there is no minimum length
Must contain at least one option when present.
Optional. Omitted and `null` are equivalent and mean no titled single-select choices are
declared by `oneOf`.
</ResponseField>
<ResponseField name="pattern" type={"string | null"} >
Pattern the string must match, in ECMA-262 regular expression syntax.

Optional. Omitted and `null` are equivalent and mean there is no pattern constraint.

- Format: `regex`

</ResponseField>
<ResponseField name="title" type={"string | null"} >
Optional title for the property.
Expand Down Expand Up @@ -11505,14 +11497,6 @@ Optional. Omitted and `null` are equivalent and mean there is no minimum length
Must contain at least one option when present.
Optional. Omitted and `null` are equivalent and mean no titled single-select choices are
declared by `oneOf`.
</ResponseField>
<ResponseField name="pattern" type={"string | null"} >
Pattern the string must match, in ECMA-262 regular expression syntax.

Optional. Omitted and `null` are equivalent and mean there is no pattern constraint.

- Format: `regex`

</ResponseField>
<ResponseField name="title" type={"string | null"} >
Optional title for the property.
Expand Down
19 changes: 9 additions & 10 deletions docs/protocol/v2/elicitation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,15 @@ progress actually resumes. `elicitation/complete` is not itself a state update.
`requestedSchema` is a flat object with `type: "object"`, `properties`, and
optional `required`, `title`, and `description`. Each property is one of:

| Property | Schema | Optional keywords |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| Text | `type: "string"` | `minLength`, `maxLength`, `pattern`, `format` (`email`, `uri`, `date`, `date-time`), `default` |
| Single select | `type: "string"` with `enum` (values) or `oneOf` (`const` and `title` options) | `default` |
| Number | `type: "number"` or `type: "integer"` | `minimum`, `maximum`, `default` |
| Boolean | `type: "boolean"` | `default` |
| Multi select | `type: "array"` with `items` of `{ "type": "string", "enum": [...] }` or `{ "anyOf": [...] }` (`const` and `title` options) | `minItems`, `maxItems`, `default` |

Every property may also have `title` and `description`. `pattern` uses
ECMA-262 regular expression syntax, as in JSON Schema. Clients treat an unknown
| Property | Schema | Optional keywords |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| Text | `type: "string"` | `minLength`, `maxLength`, `format` (`email`, `uri`, `date`, `date-time`), `default` |
| Single select | `type: "string"` with `enum` (values) or `oneOf` (`const` and `title` options) | `default` |
| Number | `type: "number"` or `type: "integer"` | `minimum`, `maximum`, `default` |
| Boolean | `type: "boolean"` | `default` |
| Multi select | `type: "array"` with `items` of `{ "type": "string", "enum": [...] }` or `{ "anyOf": [...] }` (`const` and `title` options) | `minItems`, `maxItems`, `default` |

Every property may also have `title` and `description`. Clients treat an unknown
`format` as plain text. Accepted `content` maps each answered property name to its value: a string for text and single-select properties, a number for `number` and `integer`, a boolean for `boolean`, and an array of strings for multi-select. Unanswered properties are omitted, not set to `null`. Custom or future property types may use other JSON values.

Clients **SHOULD** validate submitted values before responding, and Agents
Expand Down
Loading
Loading