| 23 | } |
| 24 | |
| 25 | func parseReadDirInput(input any) (*readDirParams, error) { |
| 26 | result := &readDirParams{} |
| 27 | |
| 28 | if input == nil { |
| 29 | return nil, fmt.Errorf("input is required") |
| 30 | } |
| 31 | |
| 32 | if err := utilfn.ReUnmarshal(result, input); err != nil { |
| 33 | return nil, fmt.Errorf("invalid input format: %w", err) |
| 34 | } |
| 35 | |
| 36 | if result.Path == "" { |
| 37 | return nil, fmt.Errorf("missing path parameter") |
| 38 | } |
| 39 | |
| 40 | if result.MaxEntries == nil { |
| 41 | maxEntries := ReadDirDefaultMaxEntries |
| 42 | result.MaxEntries = &maxEntries |
| 43 | } |
| 44 | |
| 45 | if *result.MaxEntries < 1 { |
| 46 | return nil, fmt.Errorf("max_entries must be at least 1, got %d", *result.MaxEntries) |
| 47 | } |
| 48 | |
| 49 | if *result.MaxEntries > ReadDirHardMaxEntries { |
| 50 | return nil, fmt.Errorf("max_entries cannot exceed %d, got %d", ReadDirHardMaxEntries, *result.MaxEntries) |
| 51 | } |
| 52 | |
| 53 | return result, nil |
| 54 | } |
| 55 | |
| 56 | func verifyReadDirInput(input any, toolUseData *uctypes.UIMessageDataToolUse) error { |
| 57 | params, err := parseReadDirInput(input) |