@@ -131,6 +131,7 @@ class Field extends OrganicField implements JsonSerializable
131131 public $ label ;
132132
133133 public $ toolInputSchemaCallback = null ;
134+
134135 /**
135136 * Create a new field.
136137 *
@@ -753,8 +754,6 @@ public function image(): Image
753754
754755 /**
755756 * Guess the field type based on validation rules, field class, and attribute patterns.
756- *
757- * @return string
758757 */
759758 public function guessFieldType (): string
760759 {
@@ -787,7 +786,7 @@ protected function guessTypeFromFieldClass(): ?string
787786 {
788787 $ className = class_basename (static ::class);
789788
790- return match ($ className ) {
789+ return match ($ className ) {
791790 'Boolean ' , 'BooleanField ' => 'boolean ' ,
792791 'Number ' , 'Integer ' , 'Decimal ' , 'Float ' => 'number ' ,
793792 'Email ' => 'string ' ,
@@ -817,6 +816,7 @@ protected function guessTypeFromValidationRules(): ?string
817816 if (is_object ($ rule )) {
818817 return get_class ($ rule );
819818 }
819+
820820 return (string ) $ rule ;
821821 })->toArray ();
822822
@@ -855,7 +855,7 @@ protected function guessTypeFromAttributeName(): ?string
855855 {
856856 $ attribute = $ this ->attribute ;
857857
858- if (!is_string ($ attribute )) {
858+ if (! is_string ($ attribute )) {
859859 return null ;
860860 }
861861
@@ -917,7 +917,6 @@ protected function hasAnyRule(array $ruleStrings, array $rulesToCheck): bool
917917 /**
918918 * Set a custom callback for defining the tool schema.
919919 *
920- * @param callable|Closure $callback
921920 * @return $this
922921 */
923922 public function toolSchema (callable |Closure $ callback ): self
@@ -935,6 +934,7 @@ public function resolveToolSchema(ToolInputSchema $schema, Repository $repositor
935934 // Check if there's a custom callback defined
936935 if (is_callable ($ this ->toolInputSchemaCallback )) {
937936 call_user_func ($ this ->toolInputSchemaCallback , $ schema , $ repository , $ this );
937+
938938 return $ this ;
939939 }
940940
@@ -947,7 +947,7 @@ public function resolveToolSchema(ToolInputSchema $schema, Repository $repositor
947947 $ fieldType = $ this ->guessFieldType ();
948948
949949 // Add the field to schema based on its type
950- $ schemaField = match ($ fieldType ) {
950+ $ schemaField = match ($ fieldType ) {
951951 'boolean ' => $ schema ->boolean ($ attribute ),
952952 'number ' => $ schema ->number ($ attribute ),
953953 'array ' => $ schema ->string ($ attribute ), // Arrays are typically sent as JSON strings
@@ -978,27 +978,27 @@ protected function generateFieldDescription(Repository $repository): string
978978
979979 // Add validation rules information
980980 $ rules = $ this ->getStoringRules ();
981- if (!empty ($ rules )) {
981+ if (! empty ($ rules )) {
982982 $ ruleDescriptions = $ this ->formatValidationRules ($ rules );
983- if (!empty ($ ruleDescriptions )) {
984- $ description .= " . Validation: " . implode (', ' , $ ruleDescriptions );
983+ if (! empty ($ ruleDescriptions )) {
984+ $ description .= ' . Validation: ' . implode (', ' , $ ruleDescriptions );
985985 }
986986 }
987987
988988 // Add relationship information for relationship fields
989989 if ($ this ->isRelationshipField ()) {
990- $ description .= " . This is a relationship field " ;
990+ $ description .= ' . This is a relationship field ' ;
991991 }
992992
993993 // Add file information for file fields
994994 if ($ this instanceof File) {
995- $ description .= " . Upload a file " ;
995+ $ description .= ' . Upload a file ' ;
996996 }
997997
998998 // Add examples based on field type and name
999999 $ examples = $ this ->generateFieldExamples ();
1000- if (!empty ($ examples )) {
1001- $ description .= " . Examples: " . implode (', ' , $ examples );
1000+ if (! empty ($ examples )) {
1001+ $ description .= ' . Examples: ' . implode (', ' , $ examples );
10021002 }
10031003
10041004 return $ description ;
@@ -1010,8 +1010,9 @@ protected function generateFieldDescription(Repository $repository): string
10101010 protected function isRequired (): bool
10111011 {
10121012 $ rules = $ this ->getStoringRules ();
1013+
10131014 return in_array ('required ' , $ rules ) ||
1014- collect ($ rules )->contains (function ($ rule ) {
1015+ collect ($ rules )->contains (function ($ rule ) {
10151016 return is_string ($ rule ) && str_starts_with ($ rule , 'required ' );
10161017 });
10171018 }
@@ -1036,18 +1037,18 @@ protected function formatValidationRules(array $rules): array
10361037
10371038 foreach ($ rules as $ rule ) {
10381039 if (is_string ($ rule )) {
1039- $ formatted [] = match (true ) {
1040+ $ formatted [] = match (true ) {
10401041 $ rule === 'required ' => 'required ' ,
1041- str_starts_with ($ rule , 'min: ' ) => 'minimum ' . substr ($ rule , 4 ) . ' characters ' ,
1042- str_starts_with ($ rule , 'max: ' ) => 'maximum ' . substr ($ rule , 4 ) . ' characters ' ,
1043- str_starts_with ($ rule , 'between: ' ) => 'between ' . str_replace (', ' , ' and ' , substr ($ rule , 8 )),
1042+ str_starts_with ($ rule , 'min: ' ) => 'minimum ' . substr ($ rule , 4 ). ' characters ' ,
1043+ str_starts_with ($ rule , 'max: ' ) => 'maximum ' . substr ($ rule , 4 ). ' characters ' ,
1044+ str_starts_with ($ rule , 'between: ' ) => 'between ' . str_replace (', ' , ' and ' , substr ($ rule , 8 )),
10441045 $ rule === 'email ' => 'valid email format ' ,
10451046 $ rule === 'url ' => 'valid URL format ' ,
10461047 $ rule === 'numeric ' => 'numeric value ' ,
10471048 $ rule === 'integer ' => 'integer value ' ,
10481049 $ rule === 'boolean ' => 'boolean value (true/false) ' ,
10491050 $ rule === 'array ' => 'array format ' ,
1050- str_starts_with ($ rule , 'in: ' ) => 'allowed values: ' . str_replace (', ' , ', ' , substr ($ rule , 3 )),
1051+ str_starts_with ($ rule , 'in: ' ) => 'allowed values: ' . str_replace (', ' , ', ' , substr ($ rule , 3 )),
10511052 default => $ rule
10521053 };
10531054 }
@@ -1064,7 +1065,7 @@ protected function generateFieldExamples(): array
10641065 $ attribute = strtolower ($ this ->attribute );
10651066 $ fieldType = $ this ->guessFieldType ();
10661067
1067- return match ($ fieldType ) {
1068+ return match ($ fieldType ) {
10681069 'boolean ' => ['true ' , 'false ' ],
10691070 'number ' => $ this ->getNumberExamples ($ attribute ),
10701071 'array ' => ['["item1", "item2"] ' , '{"key": "value"} ' ],
0 commit comments