jsonSchema property
This field as a JSON Schema property, for a tool that takes it as an argument: a command's, offered to an agent.
Implementation
Map<String, Object?> get jsonSchema {
final about = help == null ? title : '$title: $help';
final description = unit == null ? about : '$about (${unit!.symbol})';
Map<String, Object?> numbers(int count, [int? most]) => <String, Object?>{
'type': 'array',
'items': <String, Object?>{'type': 'number'},
'minItems': count,
'maxItems': most ?? count,
};
return <String, Object?>{
...switch (kind) {
FieldKind.number => <String, Object?>{'type': 'number'},
FieldKind.integer => <String, Object?>{'type': 'integer'},
FieldKind.toggle => <String, Object?>{'type': 'boolean'},
FieldKind.choice => <String, Object?>{
'type': 'string',
'enum': choices,
},
FieldKind.color => numbers(3, 4),
FieldKind.vector3 => numbers(3),
_ => <String, Object?>{'type': 'string'},
},
'description': description,
if (kind == FieldKind.number || kind == FieldKind.integer) ...{
'minimum': ?min,
'maximum': ?max,
},
'default': ?defaultValue,
};
}